Testing.

Saturday, 21 January 2017

C programming langauge: C program to print list of perfect numbers up to given range.

Because  6 is the smallest perfect number in number system, so we will find list of perfect numbers   from 6 to 10000.
------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum,n,cnt=0;
printf("\nEnter number:");
scanf("%d",&n);
     for(num=6;num<=n;num++)
     {
sum=0;
for(i=1;i<=num/2;i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==num)
printf("\n%d. PERFERCT NUMBER %d. ",++cnt,num);
if(cnt==4)
break;
}
getch();
}


No comments:

Post a Comment