-
Notifications
You must be signed in to change notification settings - Fork 47
/
Muskan _2
132 lines (102 loc) · 2.43 KB
/
Muskan _2
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//leap year
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 400 == 0) {
printf("%d is a leap year.", year);
}
else if (year % 100 == 0) {
printf("%d is not a leap year.", year);
}
else if (year % 4 == 0) {
printf("%d is a leap year.", year);
}
// menu driven program
#include<cs50.h>
#include<stdio.h>
#include<math.h>
int main(void)
{
int num = get_int("Enter any number: ");
printf("Press 1 to check number is even or odd\n");
printf("Press 2 to check number is positive or negative\n");
printf("Press 3 to print square of the number\n");
printf("Press 4 to print squareroot of the number\n");
int choice = get_int("Enter your choice: ");
switch (choice)
{
case 1:
{
(num % 2 == 0? printf("num is even"): printf("num is odd"));
break;
}
case 2:
{
(num > 0 ? printf("num is positive"): ((num == 0 )? printf("num is zero"): printf("num is negative")));
break;
}
case 3:
{
float square = num * num;
printf("Square of the num is: %f\n", square);
break;
}
case 4:
{
float squaroo = sqrt(num);
printf("Squaroot of the num is: %f\n", squaroo);
break;
}
default:
printf("wrong choice\n");
}
return 0;
}
else {
printf("%d is not a leap year.", year);
}
return 0;
}
//
#include<cs50.h>
#include<stdio.h>
#include<math.h>
int main(void)
{
int num = get_int("Enter any number: ");
printf("Press 1 to check number is even or odd\n");
printf("Press 2 to check number is positive or negative\n");
printf("Press 3 to print square of the number\n");
printf("Press 4 to print squareroot of the number\n");
int choice = get_int("Enter your choice: ");
switch (choice)
{
case 1:
{
(num % 2 == 0? printf("num is even"): printf("num is odd"));
break;
}
case 2:
{
(num > 0 ? printf("num is positive"): ((num == 0 )? printf("num is zero"): printf("num is negative")));
break;
}
case 3:
{
float square = num * num;
printf("Square of the num is: %f\n", square);
break;
}
case 4:
{
float squaroo = sqrt(num);
printf("Squaroot of the num is: %f\n", squaroo);
break;
}
default:
printf("wrong choice\n");
}
return 0;
}