-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA1.c
More file actions
372 lines (325 loc) · 10.2 KB
/
Copy pathDSA1.c
File metadata and controls
372 lines (325 loc) · 10.2 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
This code base own and maintained by Tanmoy Samnata using standardization C23 (ISO/IEC 9899:2024)
*/
#include <stdio.h>
#include <math.h>
int basicArithmeticOperations()
{
int tom;
int Tom;
int error;
int a1 = 23;
float b1 = 8.5;
char c = 'u';
int d = 343;
int e = 45 + 30;
printf("The value of a is %d\n", a1);
printf("The value of b1+b1 is %f\n", b1 + b1);
printf("The addition of a and b is %f\n", a1 + b1);
printf("The division of a and b is %f\n", a1 - b1);
printf("The Multiplication of a and b is %f\n", a1 * b1);
printf("The sum of a and b is %d\n", e);
return 0;
}
int AreaOfCircle()
{
// Rule Area = PI * r * r [miter square]
const float PI = 3.41;
float radiusOfCircle;
float areaOfCircle = PI * radiusOfCircle * radiusOfCircle;
printf("Enter the radius of circle in meter");
scanf("%f", &radiusOfCircle);
printf("Area of circle is %f Meter Square", areaOfCircle);
return 0;
}
int circumferenceOfCircle()
{
// algorithm:
const float PI = 3.41;
float radiusOfCircle;
printf("Enter the radius of circle in meter\n");
scanf("%f", &radiusOfCircle);
float circumference = 2 * PI * radiusOfCircle;
printf("The circumference of Circle is %f meter\n", circumference);
//
return 0;
}
int areaOfRectangle()
{
// area of rectangle
int length = 3, breadth = 8;
int area = length * breadth;
printf("The area of this rectangle is %d", area);
return 0;
}
int areaOfRectangleFromUserGivenValue()
{
// area of rectangle from user given value
int length, breadth;
printf("What is the length of the rectangle\n");
scanf("%d", &length);
printf("What is the breadth of the rectangle\n");
scanf("%d", &breadth);
int area = length * breadth;
printf("The area of this rectangle is %d", area);
return 0;
}
int circumferenceOfRectangleFromUserGivenValue()
{
// area of rectangle from user given value
double length, breadth;
printf("What is the length of the rectangle\n");
scanf("%lf", &length);
printf("What is the breadth of the rectangle\n");
scanf("%lf", &breadth);
double circumference = 2 * (length + breadth);
printf("The circumference of this rectangle is %lf", circumference);
return 0;
}
/*
In C programming, a character variable holds ASCII value (an integer number
between 0 and 127) rather than that character itself. This integer value is the
ASCII code of the character.
For example, the ASCII value of 'A' is 65.
What this means is that, if you assign 'A' to a character variable, 65 is stored
in the variable rather than 'A' itself.
Now, let's see how we can print the ASCII value of characters in C programming.
*/
int _ASCIIcodeRendering()
{
char c1;
printf("Enter a character \n ");
scanf("%c", &c1);
// %d displays the integer value of a character
// %c displays the actual character
printf("The ASCII code of character is %d\n", c1);
return 0;
}
int AreaOFTriangle()
{
// Rule area = (Height * Base)
/*
Algorithm
Program Start
Declare Variables
Input values
calculate area of triangle
print area of triangle
Program End
*/
float area, Height, Base;
printf("Enter Height of Triangle\n");
scanf("%f", &Height);
printf("Enter Base of Triangle\n");
scanf("%f", &Base);
area = (Height * Base) / 2; // According to flow of the program
printf("Area of Triangle is %f", area);
return 0;
}
int areaOfTriangleUsingFunction()
{
/*
C Program To Find Area of Triangle Using Function
Algorithm
Program Start
Declare Variables
Input values
Calling Function to find area of triangle
calculate area of triangle
print area of triangle
Program End
Program
*/
}
int divisibilityTestByModulusOperator()
{
printf("5 when divided by 2 leaves a remainder of %d \n",
5 % 2); // Output : 5 when divided by 2 leaves a remainder of 1
printf("-5 when divided by 2 leaves a remainder of %d \n",
-5 % 2); // Output : -5 when divided by 2 leaves a remainder of -1
printf("5 when divided by -2 leaves a remainder of %d \n",
5 % -2); // output : -5 when divided by -2 leaves a remainder of 1
return 0;
}
int mistakesInCProgramming()
{
// int a2, b2, z2;
// z2 = a2 + b2;
// a2 + b2 = z2; //not allowed
// No operator assumed to be present
// printf("The value of 4 * 5 is %d \n", (4)(5)); // Wil not return 20 /wrong
// ! printf("The value of 4 * 5 is %d \n", (4) * (5)); // output: The value of
// 4 * 5 is 20
// There are no exponentiation in c
// printf("The value of 4 ^ 5 is %d \n", 4 ^ 5); // output: The value of 4 ^ 5
// is 1
printf(
"The value of 4 to te power 5 is %d \n",
pow(4, 5)); // note: include '<math.h>' or provide a declaration of 'pow'
return 0;
}
// Power of a Number Using the while Loop
int aPowerOfn()
{
int base, exp;
long double result = 1.0;
printf("Enter a base number: ");
scanf("%d", &base);
printf("Enter an exponent: ");
scanf("%d", &exp);
while (exp != 0)
{
result *= base;
--exp;
}
printf("Answer = %.0Lf", result);
return 0;
}
int powFunction()
{
// using pow Function we need <math.h>
double base, exp, result;
printf("Enter a base number: ");
scanf("%lf", &base);
printf("Enter an exponent: ");
scanf("%lf", &exp);
// calculates the power
result = pow(base, exp);
printf("%.1lf^%.1lf = %.2lf", base, exp,
result); // pow(base, exp) Allows return Flotaing point number
return 0;
}
int simpleInterest()
{
int principal = 100, rate = 4, years = 1;
double simpleInterest = (double)(principal * rate * years) / 100;
printf("Simple interest of %lf", simpleInterest);
return 0;
}
/*// // volume of this cylinder
// // int radius = 3;
// // float pi = 3.14;
// int height = 23;
// printf("the volume of this cylinder is %f\n", pi * radius * radius *
// height);
// // Celsius to fahrenheit
// float celsius = 3, fahrenheit;
// fahrenheit = (celsius * 9 / 5) + 32;
// printf("The value of this celsius temperature temperature %f", fahrenheit);
*/
int typeConversion() { return 0; }
int personNameInAbbreviated()
{
/*
Let us use character arrays fname, mname and lname to store the first name, middle name and last name of a person. The program given below first accepts the full name, i. e., values of fname, mname and lname using a scanf function. Then the name is printed in the desired abbreviated form using a printf function. The initial letters of fname and mname are printed using fname [0]and mname[0], respectively. The program is given below.*/
char fname[20], mname[20], lname[20]; /* person’s name */
/* accept full name */
printf("Enter full name (first middle last)");
scanf("%s %s %s", fname, mname, lname);
/* print abbreviated name */
printf("Abbreviated name: ");
printf("%c. %c. %s\n", fname[0], mname[0], lname);
return 0;
}
int grossSalary()
{
// HRA = Housing Revenue Allowance
// DA = Dearness Allowance is a cost of living adjustment that the Government pays to public sector employees and pensioners.
//
// ta
/*
Gross Salary = Basic Salary + Other Allowance
*/
float basic, da_percent, hra_percent, da, hra, gross_salary;
// Asking for input
printf("Enter the basic pay: ");
scanf("%f", &basic);
printf("Enter the DA percentage: ");
scanf("%f", &da_percent);
printf("Enter the HRA percentage: ");
scanf("%f", &hra_percent);
// Calculating D.A and H.R.A
da = (basic * da_percent) / 100;
hra = (basic * hra_percent) / 100;
// Calculating gross salary
gross_salary = basic + da + hra;
// Displaying output
printf("Gross salary of the employee is: %.2f", gross_salary);
return 0;
}
int percentageOf5Subjects()
{
double eng, phy, chem, math, comp;
double FM, total, average, percentage;
printf("Enter Full Marks in total: :- \n");
scanf("%lf", &FM);
printf("Enter marks in English subject: :- \n");
scanf("%lf", &eng);
printf("Enter marks in physics subject: :- \n");
scanf("%lf", &phy);
printf("Enter marks in chemistry subject: :- \n");
scanf("%lf", &chem);
printf("Enter marks in Mathematics subject: :- \n");
scanf("%lf", &math);
printf("Enter marks in computer subject: :- \n");
scanf("%lf", &comp);
total = (eng + phy + chem + math + comp);
average = (total / 5);
percentage = (total / FM) * 100;
printf("Total marks = %.2f\n", total);
printf("Total marks = %.2f\n", average);
printf("Percentage =%.2f\n", percentage);
return 0;
}
int sizeoFDataTypes()
{
printf("Size of Int Data Types in C = %2d bytes \n", sizeof(short int));
printf("Size of Long Int Data Types in C = %2d bytes \n", sizeof(long int));
printf("Size of Float Data Types in C = %2d bytes \n", sizeof(float));
printf("Size of Double Data Types in C = %2d bytes \n", sizeof(double));
printf("Size of Long Double Data Types in C = %2d bytes \n", sizeof(long double));
printf("Size of Char Data Types in C = %2d bytes \n", sizeof(char));
return 0;
}
// Error in output
int nToThePowerUsingPOWFunction()
{
// #include <math.h> to use pow( number, power);
int number, a3, b3, c3;
printf("Enter the number\n");
scanf("%d", &number);
a3 = pow(number, 1);
b3 = pow(number, 2);
c3 = pow(number, 3);
printf("%d , %d , %d", a3, b3, c3);
return 0;
}
int nToThePower()
{
int number;
printf("Enter the number\n");
scanf("%d", &number);
printf("%d , %d , %d", number, number * number, number * number * number);
return 0;
}
int factorialOfGivenNumber() // what is the logic behind this?
{
/*
Factorial of a positive integer (number) is the sum of multiplication of all the integers smaller than that positive integer. For example, factorial of 5 is 5 * 4 * 3 * 2 * 1 which equals to 120.
*/
int i, fact = 1, number;
printf("Enter a number: ");
scanf("%d", &number);
for (i = 1; i <= number; i++)
{
fact = fact * i;
}
printf("Factorial of %d is: %d", number, fact);
return 0;
}
int main()
{
nToThePower();
// nToThePowerUsingPOWFunction ();
return 0;
}