-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ36.c
73 lines (73 loc) · 1.88 KB
/
Q36.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* program :- 36.
Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
*/
#include<stdio.h>
void main()
{
int n;
do
{ printf("1. Factorial of a number\n");
printf("2. Prime or not\n");
printf("3. Odd or even\n");
printf("4. Exit\n");
printf("\nChoose the option(1,2,3,4):- ");
scanf("%d",&n);
switch(n)
{
case 1:
{
int i,a,f=1;
printf("\nEnter the number:- ");
scanf("%d",&a);
for(i=1; i<=a; i++)
{
f=f*i;
}
printf("Factorial = %d\n\n",f);
break;
}
case 2:
{
int i,a,b,j,n;
printf("\nEnter the number:- ");
scanf("%d",&n);
for ( i=2; i<n; i++)
{
if(n%i==0)
{
break;
}
}
if(n==i)
printf("%d is Prime number\n\n",n);
else
printf("%d is not prime number\n\n",n);
break;
}
case 3:
{
int i,j,n;
printf("\nEnter the number:- ");
scanf("%d",&n);
if(n%2==0)
{
printf("%d is Even number\n\n",n);
}
else
{
printf("%d is Odd number\n\n",n);
}
break;
}
case 4:
{
exit(0);
break;
}
}
}while(1);
}