Program in C to check a number is perfect or not using function
#include<stdio.h> #include<conio.h> int perfect(int n); int main() { int a,p; printf("Enter a number:-"); scanf("%d",&a); p=perfect(a); if(p==a) printf("%d is perfect no.",a); else printf("%d is not perfect no.",a); getch(); } int perfect(int n) { int sum=0,i; for(i=1;i<n;i++) { if(n%i==0) { sum+=i; } } return (sum); }Output:-
0 Comments