-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem_7_9_page_118.c
71 lines (61 loc) · 1.49 KB
/
Problem_7_9_page_118.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
/* 1: Factorial of a number
2: Prime or not
3: Odd or Even
4: Exit */
#include <stdio.h>
#include <conio.h>
int main()
{
int choice,num,i,fact;
while (choice)
{
printf("\n1. Find a factorial \n");
printf("2. Prime or not\n");
printf("3. Odd or Even\n");
printf("4.Exit\n");
printf("Enter a choice\n");
scanf("%d",&choice);
switch (choice)
{
case 1:
printf("Enter a number: \n");
scanf("%d",&num);
fact=1;
for ( i = 1; i<=num; i++)
fact = fact*i;
printf("Factorial value is = %d\n",fact);
break;
case 2:
printf("Enter a number\n");
scanf("%d",&num);
for ( i = 2; i <= num; i++)
{
if (num%i==0)
{
printf("Not a prime number\n");
break;
}
}
if (i==num)
{
printf("Prime number\n");
}
break;
case 3:
printf("Enter a number: \n") ;
scanf("%d",&num);
if (num%2==0)
{
printf("Number is a Even");
}
else
printf("number is a Odd");
break;
case 4:
exit(0) ;
default :
printf("Wrong choice");
}
}
return 0;
}