Solution:
#include <stdio.h>
void main()
{
int fig_code;
int number, originalNumber, remainder, result = 0;
int n,i=1,sum=0;
while(1)
{
printf("-------------------------\n");
printf(" 1 --> Armstrong or not\n");
printf(" 2 --> Perfect or not \n");
printf("-------------------------\n");
printf("Enter the Figure code\n");
scanf("%d", &fig_code);
switch(fig_code)
{
case 1:
printf("Enter a three digit integer: ");
scanf("%d", &number);
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
break;
case 2:
printf("Enter a number: ");
scanf("%d",&n);
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
printf("%d is a perfect number",i);
else
printf("%d is not a perfect number",i);
break;
default:
exit(0); }
}}
0 Comments