0

Does anyone know how to print the first 3 odd perfect numbers in C?

15th Aug 2021, 3:45 AM
kevin josuè mondragon nuñez
5 Réponses
+ 2
Make a program that finds the first 3 perfect numbers even and the first 3 odd perfect numbers. A perfect number is a positive integer, which is equal to the sum of all positive integers (excluding itself) that are divisors of the number. The first perfect number is 6, since its divisors are 1, 2, 3 and 1 + 2 + 3 = 6. I could already do the one of the pairs but the one of the odd ones could not eh
15th Aug 2021, 3:53 AM
kevin josuè mondragon nuñez
+ 2
kevin josuè mondragon nuñez First make a function that accepts an integer and return whether or not its a perfect number. Then inside main write a loop that keeps incrementing a number, checking if its a perfect number using that function, and if it is check if its even or odd using n%2
15th Aug 2021, 5:08 AM
Giorgos
+ 1
You already posted this question. A good addition to it would be to explain what perfect numbers are.
15th Aug 2021, 3:46 AM
Slick
Slick - avatar
+ 1
if the smallest divisor you check for evens (not including 1) is 2, then you can check: 3, 5, ect for odd numbers.
15th Aug 2021, 4:09 AM
Slick
Slick - avatar
+ 1
p=5 perfect=2**(p-1)*((2**p) -1) where, p is the prime number. ⏺️The kth perfect number has k digits. ⏺️All the perfect numbers are even. It is still unknown whether odd perfect numbers exist or not. source : https://www.cuemath.com/numbers/perfect-numbers/
15th Aug 2021, 5:47 AM
Ratnapal Shende
Ratnapal Shende - avatar