a number is perfect if it is equal to the sum of its proper
divisor..
6 is perfect number coz its proper divisors are 1,2 and
three.. and 1+2+3=6...
a number is deficient if the sum of its proper divisor is
less than the number..
sample: 8 is deficient, coz its proper divisors are 1,2 and
4, and 1+2+4=7.
abundant number, if the sum of its proper divisor is greater
than the number..
sample..12 is abundant coz 1+2+3+4+6=16 which is geater than 12.
now write a program that prompts the user for a number, then
determines whether the number is perfect,deficient and
abundant..
Answer Posted / samim
#include<conio.h>
#include<stdio.h>
int f(int x)
{ int i,c,a=0;
for(i=1;i<x;i++)
{ c=x%i;
if(c==0)
a+=i;
}
return a;
}
void main()
{ int x;
clrscr();
printf("\nenter a integer number:\n");
scanf("%d",&x);
printf("%d",f(x));
if(f(x)==x)
printf("\nthis number is prefect");
if(f(x)>x)
printf("\nthis number is abundant");
if(f(x)<x)
printf("\nthis number is deficient");
getch();
}
| Is This Answer Correct ? | 5 Yes | 5 No |
Post New Answer View All Answers
What is the modulus operator?
What is fflush() function?
What is d'n in c?
Are pointers really faster than arrays?
What is array of pointers to string?
Explain what is a pragma?
Explain main function in c?
Explain what does a function declared as pascal do differently?
How can I split up a string into whitespace-separated fields?
Why & is used in scanf in c?
Here is a good puzzle: how do you write a program which produces its own source code as output?
What do mean by network ?
What are header files in c?
Is there a built-in function in C that can be used for sorting data?
Explain how do you sort filenames in a directory?