A perfect number is a positive integer that is equal to the

A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself that divides the number evenly (i.e., no remainder). For example. 6 is a perfect number because the sum of its proper divisors 1. 2. and 3 is equal to 6. Eight is not a perfect number because 1 + 2 + 4 notequalto 8. Write a program that accepts a positive integer and determines whether the number is perfect. Also display all proper divisors of the number. Try a number between 20 and 30 and another number between 490 and 500. Write a program that displays all integers between tow and high that are the sum of the cube of their digits. In other words, find all numbers xyz such that xyz = x^3 + y^3 + z^3 for example 153 = 1^3 + 5^3+ 3^3. Try 100 for low and 1000 for high. Hey in regards to the first question I need the program to tell if the entered number is perfect of not and if it is perfect for the divisors to show. Don\'t want the divisors if it\'s not a perfect number. Thanks you guys are awesome. All Done in c Language please thanks again Before you answer please READ the question, NO DIVISORS IK ITS NOT A PERFECT NUMBER, PERFECT NUMBER =DIVISORS, NOT A PERFECT NUMBER = NO DIVISORS, THIS IS THE 7th time I\'ve posted this question So if \"it\'s a perfect number display: \"it\'s a perfect number \"and display it\'s divisors not a perfect number display:\"it\'s not a perfect number\" nothing else, don\'t want the divisors for this one.

Solution

// C code, main.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
int number,i=1,sum=0;
printf(\"Enter a number: \");
scanf(\"%d\",&number);

while(i<=number/2)
{
if(number%i==0)
{
sum=sum+i;
}
i++;
}

if(sum==number)
{
printf(\"It\'s a perfect number\ \");
printf(\"Divisors: \");
for (i = 1; i <= number/2; ++i)
{
if(number%i==0)
{
printf(\"%d \",i);
}
}
printf(\"\ \");
}
else
printf(\"It\'s not a perfect number\ \");

return 0;
}

/*
output:

Enter a number: 496
It\'s a perfect number
Divisors: 1 2 4 8 16 31 62 124 248

Enter a number: 15
It\'s not a perfect number

*/



// C code, main.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
int low;
int high;

printf(\"Enter low: \");
scanf(\"%d\",&low);
printf(\"Enter high: \");
scanf(\"%d\",&high);

for (int i = low; i <= high; ++i)
{
int number = i;
int cubeSUm = 0;
while(number!=0)
{
int t = number%10;
cubeSUm = cubeSUm + t*t*t;
number = number/10;
}

if(i == cubeSUm)
printf(\"Number: %d\ \",i);
}

return 0;
}

/*
output:

Enter low: 100
Enter high: 1000

Number: 153
Number: 370
Number: 371
Number: 407

*/

 A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself tha
 A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself tha
 A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself tha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site