To find the given no. is perfect no. (or) not
Program:
#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();
}
Output:
Case: 1
Enter a number : 6
6 is a perfect number
Case: 2
Enter a number : 28
6 is a perfect number
Case: 3
Enter a number : 12
6 is not a perfect number
-
UpdatedDec 30, 2019
-
Views6,676
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order