In this article is another simple program to show you how to solve perfect number using C language. The code is very simple and easy to understand I am using Code Blocks to write this code.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My mobile number here in the Philippines is 09173084360.
Program Listing
perfect.c
#include <stdio.h>
int main()
{
int number=0, rem=0, sum = 0, a=0;
printf("Perfect Number in C");
printf("\n\n");
printf("Enter a Number : ");
scanf("%d", &number);
for (a = 1; a <= (number - 1); a++)
{
rem = (number % a);
if (rem == 0)
{
sum = sum + a;
}
}
if (sum == number) {
printf("\n\n");
printf("The given number %d is perfect number.", number);
printf("\n\n");
}
else {
printf("\n\n");
printf("The given number %d is not a perfect number.",number);
printf("\n\n");
}
printf("\n\n");
return 0;
}
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My telephone number at home here in Bacolod City, Negros Occidental is +63 (034) 4335675.
Sample Program Output
Program Listing
perfect.c
#include <stdio.h>
int main()
{
int number=0, rem=0, sum = 0, a=0;
printf("Perfect Number in C");
printf("\n\n");
printf("Enter a Number : ");
scanf("%d", &number);
for (a = 1; a <= (number - 1); a++)
{
rem = (number % a);
if (rem == 0)
{
sum = sum + a;
}
}
if (sum == number) {
printf("\n\n");
printf("The given number %d is perfect number.", number);
printf("\n\n");
}
else {
printf("\n\n");
printf("The given number %d is not a perfect number.",number);
printf("\n\n");
}
printf("\n\n");
return 0;
}