-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculation.c
More file actions
executable file
·298 lines (288 loc) · 7.89 KB
/
Copy pathCalculation.c
File metadata and controls
executable file
·298 lines (288 loc) · 7.89 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include <stdio.h>
#include <conio.h>
void Arithematic(void); // Takes nothing,returns nothing. /*Declaration*/
void OddEven(void); // Takes nothing,returns nothing. /*Declaration*/
int G(int, int); // Takes something,returns some thing. /*Declaration*/
void G2(void); // Takes nothing,returns nothing. /*Declaration*/
int N(int); // Takes something,returns nothing. /*Declaration*/
void scale(void); // Takes nothing,returns nothing. /*Declaration*/
void scale2(void); // Takes nothing,returns nothing. /*Declaration*/
void Time(void); // Takes nothing,returns nothing. /*Declaration*/
int f1(int); // Takes nothing,returns nothing. /*Declaration*/
int main()
{
int a, b, c, choice, choice2, x, y, z, t, l, p, f, q;
char n[15];
printf("Enter your name\n");
scanf("%s", n);
printf("Welcome %s\n", &n);
printf("enter your password");
scanf("%d", &p);
if (p == 1289)
{
printf("1. Arithmatic Calculation\n");
printf("2. Greater number\n ");
printf("3. odd-Even numbers\n ");
printf("4. FirstN natural numbers\n ");
printf("5.Converter of units\n");
printf("6. Factorial\n");
printf("Enter your choice no.\n ");
scanf("%d", &choice);
switch (choice)
{
case 1:
Arithematic();
break;
case 2:
printf("1. Between two digits\n");
printf("2. Between three digits\n");
printf("Enter how many digit numbers you want to compaire ?\n");
scanf("%d", &l);
switch (l)
{
case 1:
printf("Enter two numbers for comparisons\n");
scanf("%d%d", &x, &y);
z = G(x, y);
printf("Greater number is %d\n", z); /* code */
break;
case 2:
G2(); // Takes nothing,returns nothing.
break;
default:
break;
}
break;
case 3:
OddEven();
break;
case 4:
printf("Enter a number ");
scanf("%d", &t);
printf("Sum of first %d numbers are %d",t,N(t));
break;
case 5:
printf("1. meter & centimeter\n");
printf("2. kilogram & gram\n");
printf("3. Time Calculation\n");
// printf("5. Year & month\n");
printf("enter your choice");
scanf("%d", &choice2);
switch (choice2)
{
case 1:
scale();
break;
case 2:
scale2();
break;
case 3:
Time();
break;
default:
break;
}
break;
case 6:
printf("enter a number for factorial");
scanf("%d", &f);
q = f1(f);
printf("Factorial of %d is %d",f,q);
break;
default:
printf("Invalid");
break;
}
}
else
printf("\nLol!!!! Wrong pasword!");
return 0;
}
//arithematic program//
void Arithematic() // Takes nothing,returns nothing.
{
int a, c;
char b;
printf("enter your opperation");
scanf("%d %c%d", &a, &b, &c);
switch (b)
{
case '+':
printf("Sum is %d", a + c);
/* code */
break;
case '-':
printf("Subtraction: %d", a - c);
break;
case '*':
printf("Multiplication: %d", a * c);
break;
case '/':
printf("Quotient: %d\n", a / c);
printf("Remainder: %d", a % c);
break;
default:
printf("Invalid");
break;
}
}
// odd - even ptogram //
void OddEven() // Takes nothing,returns nothing.
{
int a, b;
printf("Enter a number");
scanf("%d", &a);
b = a % 2;
if (b == 0)
printf("Even number");
else
printf("Odd number");
}
int G(int a, int b) // Takes something,returns some thing. /*Declaration*/
{
if (a > b)
return a;
else
return b;
}
void G2()
{
int a, b, c;
printf("enter three numbers for comparison\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b)
{
if (a > c)
printf("Greater number is %d", a); /* code */
else
printf("Greater number is %d", c);
}
else if (b > c)
printf("Greater number is %d", b);
else
printf("Greater number is %d", c);
}
int N(int a) // Takes something,returns Nothing. /*Declaration*/
{
if(a==1)
return 1;
else
return(a+N(a-1));
}
void scale() // Takes something,returns nothing. /*Declaration*/
{
int a, b, t;
float c;
printf("What you want to choose\n");
printf("First: Meter to centimeter\n");
printf("Second: Centimeter to meter\n");
scanf("%d", &t);
switch (t)
{
case 1:
printf("enter a number in meter\n");
scanf("%d", &a);
b = a * 100;
printf("%d in centimeter is %d\n", a, b);
break;
case 2:
printf("enter a number in centimeter\n");
scanf("%d", &a);
c = a / 100;
printf("%d in meter is %f", a, c);
}
}
void scale2() // Takes something,returns nothing. /*Declaration*/
{
int a, b, t;
float c;
printf("What you want to choose\n");
printf("First: kilogram to Gram\n");
printf("Second: Gram to kilogram\n");
scanf("%d", &t);
switch (t)
{
case 1:
printf("enter a number in kilogram\n");
scanf("%d", &a);
b = a * 1000;
printf("%d in Gram is %d\n", a, b);
break;
case 2:
printf("enter a number in Gram\n");
scanf("%d", &a);
c = a / 100;
printf("%d in Kilogram is %f", a, c);
}
}
void Time() // Takes nothing,returns nothing.
{
int a, b, c;
printf("enter what you want to calculate\n");
printf("1. Hours to minutes\n");
printf("2. Minutes to Hours\n");
printf("3. Minutes to second\n");
printf("4. Seconds to minutes\n");
printf("5. Hours to seconds\n");
printf("6. Seconds to hours\n");
scanf("%d", &a);
if (a <= 3)
{
if (a == 3)
{
printf("Enter the time in minutes");
scanf("%d", &b);
c = b * 60;
printf("%d minutes: %d seconds", b, c);
}
else if (a == 2)
{
printf("Enter the time in minutes");
scanf("%d", &b);
c = b / 60;
printf("%d minutes : %d hour", b, c); /* code */
}
else
{
printf("Enter the time in Hours");
scanf("%d", &b);
c = b * 60;
printf("%d hours : %d minutes", b, c); /* code */
}
}
else if (a > 3)
{
if (a == 4)
{
printf("Enter the time in seconds");
scanf("%d", &b);
c = b / 60;
printf("%d seconds : %d minutes", b, c); /* code */
}
else if (a == 5)
{
printf("Enter the time in Hours");
scanf("%d", &b);
c = b * 3600;
printf("%d hours : %d seconds", b, c); /* code */
}
else
{
printf("Enter the time in seconds");
scanf("%d", &b);
c = b / 3600;
printf("%d seconds : %d hours", b, c);
}
}
}
int f1(int a) // Takes something,returns something.
{
if (a == 1 || a == 0)
{
return 1;
}
else
{
return (a * f1(a - 1));
}
}