Perfect Number

#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!

Comments (0)

  • To add your comment please or

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

Got It!