0% found this document useful (0 votes)
3 views5 pages

Q15

The document describes a menu-driven C program that performs operations on an integer based on user choices, including calculating the factorial, checking if the number is odd or even, and reversing the number. The program uses a loop to display the menu and execute the selected operation until the user chooses to exit. Sample inputs and outputs are provided to illustrate the program's functionality.

Uploaded by

neehabhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Q15

The document describes a menu-driven C program that performs operations on an integer based on user choices, including calculating the factorial, checking if the number is odd or even, and reversing the number. The program uses a loop to display the menu and execute the selected operation until the user chooses to exit. Sample inputs and outputs are provided to illustrate the program's functionality.

Uploaded by

neehabhatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

NAME: ISHAN KUKRETI

UNIVERSITY ROLL NO: 24021606


SECTION: F
BRANCH: B.TECH CSE (AI)

// Write a menu driven program to perform the following operations on a given


number(integer) based upon the given choices from (1 to 4).
1. Print factorial of the number
2. Print the number is odd or even
3. Print reverse of the number
4. Exit

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

int factorial(int);

void oddeven(int);

int reverse(int);

int main()

int n,op,res;

char ch;

do

printf("****Menu****\n");

printf("1. To check the factorial \n");

printf("2. To check the number is odd/even \n");

printf("3. To reverse a number \n");

printf("4. Exit\n");

printf("Enter the choice u wanna choose: ");


scanf("%d",&op);

switch(op)

case 1:

printf("Enter the number to find its factorial: ");

scanf("%d",&n);

factorial(n);

break;

case 2:

printf("Enter the number to chck odd/even: ");

scanf("%d",&n);

oddeven(n);

break;

case 3:

printf("Enter the number to find its reverse: ");

scanf("%d",&n);

reverse(n);

break;

case 4:

exit(0);

break;

default:

printf("Invalid Choice...\n");

printf("Do you wish to continue the progarm ?? Y/y \n");

ch=getchar();

scanf("%c",&ch);
}

while( ch == 'Y' || ch == 'y' );

return 0;

int factorial(int n)

int fact=1,i;

for(i=1;i<=n;i++)

fact=fact*i;

printf("The factorial is %d\n",fact);

void oddeven(int n)

if (n%2!=0)

printf("Odd Number \n");

else

printf("Even Number \n ");

int reverse(int n)

int rev=0,d;

while(n!=0)

d=n%10;

rev=rev*10+d;
n=n/10;

printf("The reverse is %d\n",rev);

}
*****INPUT*****
****Menu****
1. To check the factorial
2. To check the number is odd/even
3. To reverse a number
4. Exit
Enter the choice u wanna choose: 1
Enter the number to find its factorial: 3

*****OUTPUT****
The factorial is 6

Do you wish to continue the progarm ?? Y/y

*****INPUT*****
****Menu****
1. To check the factorial
2. To check the number is odd/even
3. To reverse a number
4. Exit
Enter the choice u wanna choose: 3
Enter the number to find its reverse: 4891
*****OUTPUT****
The reverse is 1984

Do you wish to continue the progarm ?? Y/y

You might also like