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
#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