In this Article, you will learn C program to find the perfect number using for loop.To find the perfect number, first of all, we have to take out all divisors of that given number, then their sum, if sum is equal to that given number then it is called to be Perfect number.
- C Program to swap two number with using third variable
- C Program to find the factorial of the number
- C Program to check whether the number is Palindrome or not
- C Program to swap two number without using Third variable
- C Program to display Fibonacci in c using for loop
- C Program using Switch case to enter a digit (0-9) and write in word
- C program to print the factor of the number
C program to find the perfect number using for loop|perfect number in C |E-studyblog |
Perfect number :
A Perfect number is a positive number which is equal to the sum of its proper divisors.
For Example: 6 is a perfect number since it is divisible by 1,2 and 3.
Others Perfect numbers are :28,496 Etc
C program to find the perfect number using for loop:
/* C program to find the perfect number using for loop */ #include <stdio.h> int main(){ int i,n,s=0; printf("\nEnter an Integer:"); scanf("%d",&n); for(i=1;i<n;i++) { if(n%i==0) s=s+i; } if(s==n) printf("%d is a Perfect Number:",n); else printf("%d is not the Perfect Number:",n); return 0; }
Output:
I hope you have read our Article " C Program to find perfect of the number using for loop"and you have collected lots of information from there.If you like the post,then please comment and share among your friends and family. you can write your opinion about my post in the comment box.
Thank you!
No comments:
Post a Comment
If you have any queries ,please let us know