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

Source: Internet
Author: User

Poor Lifting Method!
/*
==================================================================
Title: For all the completed numbers within 10000, the statistic quantity and output in the following format:
28=1+2+4+7+14.
Note: The end count is the sum of all the factors that contain 1, except for itself!
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 contain 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 lies in the format of the output, the judgment is a simple problem, and can even be used for a loop to
Realize! However, in order to output the required format, all of its factors must be obtained before being saved 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 determined by the + output + reinitialization after the next n is counted. Until the N>n follow
Loop ends (Note that you cannot use a for loop, otherwise the output is repeated n times).
========================================================================
*/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The basic algorithm of C language 38-all the finished numbers in the 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.