The basic algorithm of C language 38-all finished in formatted output 10000

Source: Internet
Author: User

Poor Lifting Method!
/*
==================================================================
Title: All the numbers within 10000 are counted and output in the following format, for example:
28=1+2+4+7+14.
Note: The finish count is in addition to itself. The value equals the sum of all the factors including 1!
such as: 28 of all factors are: 1,2,4,7,28, in addition to 28 other factors and = 28, so 28 is the end of the number!
==================================================================
*/
#include <stdio.h>
#define N 10000
int ws (int a)
{
int i=1;
int sum=0;
while (I&LT;A)//does not include a, because the factor of the completion number must be less than it itself!
{
if (a%i==0)
Sum+=i;
i++;
}
if (sum==a)
return 1;
else return 0;
}
void Main ()
{
int n=2,i,j,k=0,a[100],shu=0;
printf ("The end of%d is:", N);
while (n<=n)
{
if (WS (n))
{
for (i=1;i<n;i++)
if (n%i==0)
A[k++]=i;
printf ("\n%d:%-4d=%d", shu+1,n,a[0]);
for (j=1;j<k;j++)
printf ("+%d", A[j]);
printf (". \ n");
shu++;
k=0;
}
n++;
}
printf ("\ n altogether%d", Shu);
printf ("\ n");
}
/*
======================================================================
Evaluation:
The difficulty in this problem lies in the format of the output, the inference of the completion number is a simple problem, even can use for loop to
Realize!

However, you want to export the format required by the topic. You must first find all of its factors and save it in a pre-defined
Array, first output N=A[0], followed by a for loop to output the remaining + factors. In the output ".".


It is important to note that an output is inferred + output + is initialized again after the next n is counted. Until the N>n follow
Loop ends (Note that you cannot use a for loop.) Otherwise it will output n times repeatedly).


========================================================================
*/

The basic algorithm of C language 38-all finished in formatted output 10000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.