Program :-
#include <stdio.h>
main(){
int i, num ,sum = 0;
printf("enter the number : ");
scanf("%d",&num);
for(i = 1 ; i <= num /2 ; i++)
{
if(n % i == 0){
sum = sum + i;
}
}
if ( sum == num)
printf("\n number is perfect");
else
printf("\n number is not perfect");
}
Output:-
enter the number
6
number is perfect
#include <stdio.h>
main(){
int i, num ,sum = 0;
printf("enter the number : ");
scanf("%d",&num);
for(i = 1 ; i <= num /2 ; i++)
{
if(n % i == 0){
sum = sum + i;
}
}
if ( sum == num)
printf("\n number is perfect");
else
printf("\n number is not perfect");
}
Output:-
enter the number
6
number is perfect
No comments:
Post a Comment