Write a program to print all perfect number from 1 to 1000.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int i, a, b, c, sum = 0;
clrscr ( );
printf ("\n\t LIST OF PERFECT NUMBER FROM 1 TO 1000\n\n\n");
printf ("\t\t");
for(a=1;a<=1000;a++)
{
sum=0;
for ( b = 1; b < a; b++ )
{
c = a % b;
if ( c == 0)
{
sum = sum + b;
}
}
if ( a == sum)
printf (" %d ",a);
}
getch ( );
}
Click here to contact us
No comments:
Post a Comment