The intent of this page is to collection the best program and help programmers to find good blog posts to read. Some of these blogs may not be written by Java developers, but Java developers should find it useful or interesting. Reading those blogs should be fun and often bring some fresh ideas

Sunday, February 9, 2020

C: program all Perfect Number up to Nth place

Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496

#include<stdio.h>
int isperfect(int no){
int sum=0,i=no/2,temp=no;
while(i){
if(no%i==0)
sum+=i;
i--;
}
return sum==temp;
}
void Perfect_Number(int upto){
int i;
for(i=1;i<=upto;i++){
if(isperfect(i))
printf("%d\t",i);
continue;
}
}
void main(){
int no;
printf("Enter the Number check upto Nth: ");
scanf("%d",&no);
    Perfect_Number(no);

}

output:
Enter the Number check upto Nth: 10000

6       28      496     8128

No comments:

Post a Comment

If you have any doubt . Please let me know

String Operation

String Operation Using collection Framework Sorting Order  public static void sortAccending(String s) { char[] arr = s.toCharArray(); ...

Adbox