Ex.no:3f Illustrate menu-driven Programming

AIM:

         To write a C program to illustrate menu-driven Programming.

ALGORITHM:

Step 1: Start the program.

Step 2: Read choice and num.

Step 3: Repeat till a valid choice.

Step 3a: if choice is 1

                      Check if num is Armstrong or not.

Step 3b: If choice is 2

                      Check if num is Palindrome or not.

Step 3c: If choice is 3

                      Check if num is Prime or not.

Step 4: Stop the program.

PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
    int choice,num,original,ans,r,i,flag;
    clrscr();
    do
    {
        printf("n MENU");
        printf("n 1.Check Armstrong or not");
        printf("n 2.Check Palindrome or not");
        printf("n 3.Check Prime or not");
        printf("n 4.Exit");
        printf("nEnter your choice:");
        scanf("%d",&choice);
        printf("nEnter the number:");
        scanf("%d",&num);
        original=num;
        switch(choice)
        {
            case 1:
            ans=0;
            while(num>0)
            {
                r=num%10;
                ans=ans+r*r*r;
                num=num/10;
            }
            if(ans==original)
            printf("%d is an armstrong number",original);
            else
            printf("%d is not an armstrong number",original);
            break;
            case 2:
            ans=0;
            while(num>0)
            {
                r=num%10;
                ans=ans*10+r;
                num=num/10;
            }
            if(ans==original)
            printf("%d is palindrome",original);
            else
            printf("%d is not palindrome",original);
            break;
            case 3:
            flag=0;
            for(i=2;i<num/2;i++)
            {
                if(num%i==0)
                {
                    flag=1;
                    break;
                }
                else
                continue;
            }
            if(flag==1)
            printf("%d is not a prime number",num);
            else
            printf("%d is a prime number",num);
            break;
            default:
            exit(0);
        }
    }while(1);
}
OUTPUT:

menu

RESULT:

                    Thus the C program to illustrate menu-driven Programming is written and executed successfully.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *