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

Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number 1. Write the definitions for each of the above member functions. 2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.

Assume that a bank maintains two kinds of accounts, are called as saving account and current account. The saving account provides compound interest and withdrawal facilities but no cheque book facility. The current account provides cheque book facility but no interest. Current account holders should also maintain a minimum balance and if the balance falls below the level, a service charge is imposed. Create a class account that stores customer name, account number and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks: a.Include constructor for all the three classes. b.Accept deposit amount from the customer and update the balance. c.Display the balance. d.Compute and deposit interest. e.Permit withdrawal and update the balance. f. Check for minimum balance, impose penalty, necessary and update the balance.