Home » Sometech » a menu driven program to check 1. a number is even or odd 2. prime or not 3. factorial of the number.

a menu driven program to check 1. a number is even or odd 2. prime or not 3. factorial of the number.

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

void main()

{

           int a,d,t,choice,i,j;

           long int fact=1;

           clrscr();

           printf(“\nEnter the number “);

           scanf(“%d”,&a);

           printf(“\n*********************”);

           printf(“\n* 1. Even or Odd    *”);

           printf(“\n* 2. Prime or not   *”);

           printf(“\n* 3. Factorial      *”);

           printf(“\n* 4. Exit           *”);

           printf(“\n*********************”);

do

{

           printf(“\n\nEnter choice =>”);

           scanf(“%d”,&choice);

switch(choice)

{

      case 1:if(a%2==0)

           printf(“\n%d is EVEN “,a);

        else

           printf(“\n%d is ODD “,a);

                  break;

      case 2:if(a==2)

           printf(“\n%d is the first prime number”,a);

        else

{

                  t=sqrt(a);

                        d=2;

       while(d<=t)        

{

        if(a%d==0)

                    break;

                    d++;

}

        if(d>t)

               printf(“\n%d is a prime number”,a);

        else

                     printf(“\n%d is not a prime number”,a);

 }

                    break;

      case 3:

                     for( j=1;j<=a;j++)

                                fact=fact*j;

                     printf(“\n%d Factorial is %ld”,a,fact);

                     break;

         case 4: exit(0);

   default: printf(“\nChoice is wrong!!!”);

}

}

while(choice<=4);

            getch();

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: