# include <stdio.h>
# include <conio.h>
# include <math.h>
void main()
{
int i, n, s = 0 ;
clrscr() ;
printf("Enter a number : ") ;
scanf("%d", &n) ;
for(i = 1 ; i < n ; i++)
{
if(n % i == 0)
s = s + i ;
}
if (s == n)
printf("\n%d is a perfect number", n) ;
else
printf("\n%d is not a perfect number", n) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter a number : 6
6 is a perfect number
RUN 2 :
~~~~~~~
Enter a number : 28
28 is a perfect number
RUN 3 :
~~~~~~~
Enter a number : 12
12 is not a perfect number
# include <conio.h>
# include <math.h>
void main()
{
int i, n, s = 0 ;
clrscr() ;
printf("Enter a number : ") ;
scanf("%d", &n) ;
for(i = 1 ; i < n ; i++)
{
if(n % i == 0)
s = s + i ;
}
if (s == n)
printf("\n%d is a perfect number", n) ;
else
printf("\n%d is not a perfect number", n) ;
getch() ;
}
RUN 1 :
~~~~~~~
Enter a number : 6
6 is a perfect number
RUN 2 :
~~~~~~~
Enter a number : 28
28 is a perfect number
RUN 3 :
~~~~~~~
Enter a number : 12
12 is not a perfect number
No comments:
Post a Comment