//what is a perfect number
// A perfect number is a number whose sum of factors is equal to same number
//example: 6 who factors are 1, 2, 3 and their sum equal to 6. The next perfect number is 28Â =Â 1Â +Â 2Â +Â 4Â +Â 7Â +Â 14. This is followed by the perfect numbers 496 and 8128
Proceedure for checking perfect number:
start
1. initilize sum =0:
2. from i= 1 to n-1
3. check if i is factor of n i.e n%i==0
4. sum=sum + i
5. Go back to step 2
4. If sum==n the "number is perfect" else" not perfect";
end
// A perfect number is a number whose sum of factors is equal to same number
//example: 6 who factors are 1, 2, 3 and their sum equal to 6. The next perfect number is 28Â =Â 1Â +Â 2Â +Â 4Â +Â 7Â +Â 14. This is followed by the perfect numbers 496 and 8128
Proceedure for checking perfect number:
start
1. initilize sum =0:
2. from i= 1 to n-1
3. check if i is factor of n i.e n%i==0
4. sum=sum + i
5. Go back to step 2
4. If sum==n the "number is perfect" else" not perfect";
end
//check a number is perfect or not using c program
//write a perfect number program in c
/C Program to find a number is perfect or not
#include<stdio.h>
void main(){
int n,i=1,sum=0;
printf("\nEnter a number:-");
scanf("%d",&n);
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("\nThe no %d is a perfect number",i);
else
printf("\nThe no %d is not a perfect number",i);
}
}
No comments:
Post a Comment