by Dinesh Thakur Category: Control Structures

 

#include<iostream.h>
#include<conio.h>
void main()
{
      int choice, num, i ;
      unsigned long int fact;
      clrscr();
      while (1)
        {
              cout<<"1. Factorial\n";
              cout<<"2. Prime\n";
              cout<<"3. Odd / Even\n";
              cout<<"4. Exit\n";
              cout<<'\n Your choice ?";
              cin>>choice ;
              switch ( choice)
                     {
                         case 1 :
                                       cout<<"\n Enter number:";
                                       cin>>num ;
                                       fact = 1 ;
                                       for (i=1 ;k=num ;i++)
                                       fact = fact * i;
                                       cout<<''\n Factorial value = \n"<< fact;
                                       break ;     
                         case 2 :
                                      cout<<''\n Enter number:";
                                      cin>>num ;
                                      for(i=2;i<num;i++ )
                                          {
                                              if (num%i== 0 )
                                                {
                                                   cout<<'\n Not a prime number.\n";
                                                   break ; 
                                                }
                                         }
                                             if (i==num)
                                                cout<<''\n Prime number.\n";
                                                break;
                         case 3 :
                                          cout<<'\nEnter number:";
                                          cin>>num ;
                                      if ( num %2==0 )
                                          cout<<''\n Even number.\n";
                                      else
                                          cout<<'\nOdd number.\n";
                                          break;
                          case 4 :
                                      exit( ) ;
                     }
          }
                                     getch();
}

C++ Menu Driven Program



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles