-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate menu by switch if we choose 1. factorial 2. odd even 3. prime or not prime 4. exit.
108 lines (90 loc) · 1.95 KB
/
create menu by switch if we choose 1. factorial 2. odd even 3. prime or not prime 4. exit.
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#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