-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment2.cpp
More file actions
56 lines (47 loc) · 993 Bytes
/
assignment2.cpp
File metadata and controls
56 lines (47 loc) · 993 Bytes
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
//Write a menu driven program to calculate having options: a) Factorial of a number. b) Odd or Even. c) Area of circle. d) Exit.
#include <stdio.h>
#define PI 3.14
int main()
{
char ch,q;
int i,n,f;
float r;
while (ch!= 'd')
{
printf(" enter \n a to get a factorial of a number \n b to know odd or even \n c to find area of a circle \n d to exit \n");
scanf("%c", &ch);
switch (ch)
{
case 'a':
printf(" enter any number");
scanf("%d", &n);
for (i=1;i<=n;i++)
{
f= f*i;
}
printf(" the factorial is %d", f);
break;
case 'b':
printf(" enter the number");
scanf("%d", &n);
if (n %2 ==0)
{
printf(" even");
}
else
{
printf(" odd");
}
break;
case 'c':
printf(" enter the radius");
scanf(" %f", &r);
printf(" area of circle is %f", PI*r*r);
break;
default:
printf(" invalid");
break;
}
}
return 0;
}