PROCEDURE:-
1.input an interger value n
2. set sum to 0
2.start finding modulo value for n with i=1 to n-1 value incrementing i by 1 each time
3.if at any point remainder is 0 add i to sum
4.if sum is same as the original input n then n is perfect number
5.else n is not perfect number
CODE:-
#include<stdio.h>
void main()
{
int n ,i,s=0
printf(“enter a number “);
scanf(“%d”,&n);
for(i=1;i<n;i++)
{
if (n % i = = 0)
s=s+i;
}
if (n = = s)
printf(“the given number %d is perfect number “,n);
else
printf(“the given number %d is not a perfect number “,n);
}
Input:- enter a number 6
Output:-the given number 6 is perfect number
1.input an interger value n
2. set sum to 0
2.start finding modulo value for n with i=1 to n-1 value incrementing i by 1 each time
3.if at any point remainder is 0 add i to sum
4.if sum is same as the original input n then n is perfect number
5.else n is not perfect number
CODE:-
#include<stdio.h>
void main()
{
int n ,i,s=0
printf(“enter a number “);
scanf(“%d”,&n);
for(i=1;i<n;i++)
{
if (n % i = = 0)
s=s+i;
}
if (n = = s)
printf(“the given number %d is perfect number “,n);
else
printf(“the given number %d is not a perfect number “,n);
}
Input:- enter a number 6
Output:-the given number 6 is perfect number
Comments
Post a Comment