Slip 25 - B) Write a menu driven program for the following option 1. Check input number is Armstrong or not 2. Check input number is Perfect or not

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);    }
}}

Post a Comment

0 Comments