A perfect number is a positive integer that is equal to the sum of its proper di
ID: 3788564 • Letter: A
Question
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 low 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.Explanation / Answer
1---
#include<stdio.h>
int main()
{
int i,num,sum=0;
printf("enter any number to check perfect number");
scanf("%d,"&num);
for(i=1;i<num;i++)
{
if(num%i==0)
{
sim+=i;
}
}
/* check whether the sum of proper divisor is equal to num
if(sum==num)
{
printf(" %d is a perfect number",num);
}
else
{
priintf(" %dis not a perfect number",num);
}
return 0;
}
2.-----ans
#include<stdio.h>
int main()
{
int n,sum=0;
printf("enter number");
scanf("%d",&n);
sum=(n*n*(n+1)*(n+1)/4;
printf("%d",sum);
return 0;
}
or
#include<stdio.h>
#include<conio.h>
void main()
{
int c,temp, sum,p;
printf("armstrong number between 1 to 1000are:");
printf("numbers like number=cube(digit1)+cube(digit2)+cube(digit3) ");
printf("153=cube(1)+cube(2)+cube(3)");
printf("numbers ARE:");
for(i=0;i<=1000;i++)
{
sum=0;p=i;
while(p>0)
{temp=p%10;
sum+=(temp*temp*temp);
p=p/10;
}
if(sum==i)
{
printf(" %d",i);
}
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.