What is Perfect Number?

Also, a perfect number is that number whose sum of its proper positive divisor(including the number itself) is equals to the twice the number.
For example 28,
divisor of 28:1,2,4,7,14,28
sum of divisors(excluding the number itself):1+2+4+7+14=28 i.e, equals to the number 28.
or, sum of divisors(including the number itself):1+2+4+7+14+28=56 i.e, equals to twice the number(2 * 28 = 56).
Logic behind the program:
- Take the two intervals from the user.
- Run a for loop from i to last interval, where i is first interval and increment i by 1 in each iteration.
- Withing that for loop run another for loop which will find the perfect numbers and print it.
Similar Problem:
Problem Statement:
Write a program in C which will find all the perfect numbers between two intervals given by the user.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #include } } |
Output:
More Topics on C program
- C program to find the length of a string without strlen( ) function
- C program to find the Armstrong Number between intervals
- C program to check whether a certain number is Armstrong or not
- C Program to Check Whether a Number is Palindrome or Not
- C Program to display the Fibonacci Series up-to n number of terms
- C Program to display the Fibonacci Series up-to a certain number
- C program to find the factorial of a number
- C Program to Find Prime Numbers Between Intervals Using Functions.
- C program: perfect or not checking
- C program to identify a number as even or odd
- C Program to print Hello World
No comments:
Post a Comment