![](https://i-blog.csdnimg.cn/blog_migrate/4b8d36739fb1484546b63b18d535f421.png)
完美数c语言程序
Here you will get program for perfect number in C.
在这里,您将获得C中完美数字的程序。
Perfect number is a positive number which is equal to the sum of all its divisors excluding itself.
完美数是一个正数,等于其除自身以外的所有除数的总和。
For example:
例如:
28 is a perfect number as 1 + 2 + 4 + 7 + 14 = 28.
28是一个完美数字,因为1 + 2 + 4 + 7 + 14 = 28。
15 is not perfect number as 1 + 3 + 5 is not equal to 15.
15不是完美数字,因为1 + 3 + 5不等于15。
Below I have shared a program to check whether a number is a perfect number or not.
下面,我共享了一个程序来检查数字是否为完美数字。
C语言中的完美数程序 (Program for Perfect Number in C)
#include<stdio.h>
int main(){
int num,j,s=0;
printf("Enter a number:");
scanf("%d",&num);
for(j=1;j<num;++j){
if(num%j==0){
s=s+j;
}
}
if(s==num){
printf("Perfect Number");
}
else{
printf("Not perfect number");
}
return 0;
}
Output
输出量
![Perfect Number in C](https://i-blog.csdnimg.cn/blog_migrate/98426052966fa90795d3ca2a2c4ba9b6.png)
翻译自: https://www.thecrazyprogrammer.com/2016/02/perfect-number-in-c.html
完美数c语言程序