Tue May 22 2018

Perfect Number

C Programming1319 views

File Name: perfect-number.c

#include<stdio.h>

int main() {
	int no, i = 1, sum = 0;
	printf("Check the given number is Perfect Number or not\n");
	printf("Enter a number:\n");
	scanf("%d", &no);

	/* Loop the process using "while loop" */
	while(i < no) {
		if(no % i == 0)
			sum += i;
		i++;
	}
	if(sum == no)
		printf("It's a Perfect Number!\n");
	else
	printf("It's not a Perfect Number!\n");
	return 0;
}


/* Output */
Check the given number is Perfect Number or not
Enter a number:
6

It's a Perfect Number!

/* ---------------------------------------- */

Check the given number is Perfect Number or not
Enter a number:
8

It's not a Perfect Number!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.