wap a program to create menu by switch if we choose 1. factorial 2. odd even 3. prime or not prime 4. exit.

 




#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
 main()
{
   int fact=1,i,a,no,choice,p=0;
   
   while (1)
   {
       printf("\n1 factorial");
       printf("\n2 odd even");
       printf("\n3 prime number or not");
       printf("\n4 exit");


       printf("\n select a opt ");
       scanf(" %d",&choice);
    switch(choice)
    {
        case 1 :
                 printf("enter any no.");
                 scanf(" %d",&no);
                 for(i=1;i<=no;i++)
                 {
                    fact*=i;
                 }
                 printf("your factorial is %d",fact);
                 break;

        case 2 :
                 printf("enter a no.");
                 scanf("%d",&no);
                 if(no%2==0)
                 printf("it is even no.");
                 else
                 printf("no. is odd");
                 break;

        case 3 :
                 printf("select a no.");
                 scanf("%d",&no);
                 for (a=1;a>=no;a++)
                 {
                    if (no%a==0)
                     {
                         p++;
                     }
                 }
                   if(p==2)
                    {
                       printf("%d is not a prime number",no);
                    }
                   else
                   {
                      printf("%d is a prime number",no); 
                   }
                   break;

        case 4 : exit (0) ;
        default : printf("u choose wrong");
     }
   }


}


output :

1 factorial 2 odd even 3 prime number or not 4 exit select a opt 1 enter any no.7 your factorial is 5040
1 factorial 2 odd even 3 prime number or not 4 exit select a opt 2 enter a no.23 no. is odd
1 factorial 2 odd even 3 prime number or not 4 exit select a opt3 select a no.23 23 is a prime number
1 factorial 2 odd even 3 prime number or not 4 exit select a opt 5 u choose wrong
1 factorial 2 odd even 3 prime number or not 4 exit select a opt 4

Comments

Popular Post

Define a class to represent a Bank Account. Include the following members: Data Members: i. Name of the depositor ii. Account number iii. Type of account iv. Balance amount in the account Member Functions: 1. To Input initial values 2. To deposit an amount 3. To withdraw an amount after checking the balance 4. To display name and balance Also write constructor for this class that takes four arguments. It should also handle type of account as savings by default