C Assignments
C Assignments
5 /* Q.1) Write a 'C' program to calculate the Area and circumference of a circle. */
6 #include <stdio.h>
8 void main()
9 {
10 float r, c, a;
11
13 scanf("%f", &r);
14
15 float pi = 3.14;
16
17 c = 2 * pi * r;
18 a = pi * r * r;
19
22 }
23
24 /* Output of Q.1 ::
26
29 */
30
31 /***************************************************************************************/
32
34 #include <stdio.h>
35
36 int main()
37 {
39
41 scanf("%f", &principle);
42
44 scanf("%f", &time);
45
47 scanf("%f", &rate);
48
50
52
53 return 0;
54 }
55
56 /* Output of Q.2 ::
localhost:64631 1/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
58 Enter time(Years) : 2
59 Enter rate(%) : 12
61 */
62
63 /***************************************************************************************/
64
65 /* Q.3) Write a 'C' program to convert temperature from degree centigrade to Fahrenheit. */
66 #include <stdio.h>
67
68 int main()
69 {
71
73 scanf("%f", &cel);
74
76
78
79 return 0;
80 }
81
82 /* Output of Q.3 ::
84
86 */
87
88 /***************************************************************************************/
89
90 /* Q.4) Write a 'C' program to calculate sum of 5 subjects and find percentage. */
91 #include <stdio.h>
92
93 int main()
94 {
95
98
101
104
107
110
113
localhost:64631 2/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
116
119
120 return 0;
121 }
122
131 */
132
133 /***************************************************************************************/
134
135 /* Q.5) Write a 'C' program to swap two integers using temporary variable. */
137
139 {
141
144
147
148 temp = x;
149 x = y;
150 y = temp;
151
153 return 0;
154 }
155
160 x=18
161 y=14
162 */
163
164 /***************************************************************************************/
165
168
170 {
171 int x, y, z;
localhost:64631 3/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
172
175
178
181
184 else
185 {
186 if (y < z)
188 else
190 }
192
193 }Biggest
194
199
201 */
202
203 /***************************************************************************************/
204
207
209 {
210 int x, y, z;
211
214
217
220
223
224 else
225 {
226 if (y > z)
228 else
localhost:64631 4/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
229 printf("\n z is Biggest Number : %d", z);
230 }
231
233 }
234
239
241 */
242
243 /***************************************************************************************/
244
245 /* Q.8) Write a 'C' program to swap two integers without using temporary variable. */
247
249 {
250 int a, b;
251
254
257
258 a = a + b;
259 b = a - b;
260 a = a - b;
261
263
264 return 0;
265 }
266
270
272 */
273
274 /***************************************************************************************/
275
276 /* Q.9) Write a 'C' program to accept character & display its ASCII value and its next &
279
281 {
283
localhost:64631 5/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
286
290 }
291
294
298 */
299
300 /***************************************************************************************/
301
302 /* Q.10) Write a 'C' program for a menu driven program which has following options:
305 3. Exit */
308
310 {
312
313 while (c != 4)
314 {
318
320 {
321 case 1:
324 n = num;
327 {
330 }
332 break;
333
334 case 2:
337 n = num;
338
339 if (num % 2 == 0)
341 else
localhost:64631 6/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
343 break;
344
345 case 3:
346 printf("\nExit");
347 break;
348 }
349 }
350 }
351
355 3. Exit
356
358
359 Exit
362 3. Exit
363
366
368
369
372 3. Exit
373
375 */
376
377 /***************************************************************************************/
378
379 /* Q.11) Write a 'C' program to calculate the sum of first n even numbers. */
381
383 {
384 int i = 1, n, p = 0;
385
388
390
392 {
393 if (i % 2 == 0)
394 {
396 p = p + i;
397 }
398 }
399
localhost:64631 7/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
401 return 0;
402 }
403
406
408
409 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
410
411 42 44 46 48 50 52 54
412
414 */
415
416 /***************************************************************************************/
417
418 /* Q.12) Write a 'C' program to print the ASCII value of any given character */
420
422 {
423 char c;
424
427
429
430 return 0;
431 }
432
436 */
437
438 /***************************************************************************************/
439
440 /* Q.13) Write a 'C' program, which accepts a character from the user and checks if it
444
446 {
447 char a;
448
451
452 if ((a >= 65 && a <= 90) || (a >= 97 && a <= 122))
453 {
455 if (isupper(a))
456 {
localhost:64631 8/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
457 a = tolower(a);
459 }
460 else
461 {
462 a = toupper(a);
464 }
465 }
466
468 {
470 }
471
472 if ((a >= 58 && a <= 64) || (a >= 91 && a <= 96) ||
473 (a >= 33 && a <= 47) || (a >= 123 && a <= 126))
474 {
476 }
477
478 return 0;
479 }
480
483
485 */
486
487 /***************************************************************************************/
488
489 /* Q.14) Write a 'C' program to take input student age and check whether given student
491 #include<stdio.h>
492
494 {
496
498 scanf("%d",&datta);
499
500 if (datta>=18)
501 {
503 }
504
505 else
506 {
508 }
509
510 return 0;
511 }
512
localhost:64631 9/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
516 */
517
518 /***************************************************************************************/
519
520 /* Q.15) Write a menu-driven program using Switch case to calculate the following:
525
529 {
532
537
539
541 {
542 case 1:
543 {
547
549 output(result);
550
551 break;
552 }
553
554 case 2:
555 {
559
561 output(result);
562
563 break;
564 }
565
566 case 3:
567 {
localhost:64631 10/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
571
573 output(result);
574
575 break;
576 }
577
578 default:
580 }
581
582 return 0;
583 }
585 {
588
590 }
592 {
594 }
595
603 */
604
605 /***************************************************************************************/
606
607 /* Q.16) Write a 'C' program that takes a number as input from user and checks whether
610
612 {
614
617
618 if (num % 2 == 0)
620 else
622
623 return 0;
624 }
625
localhost:64631 11/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
628 21 is odd.
629 */
630
631 /***************************************************************************************/
632
633 /* Q.17) Write a 'C' program to check whether the enter number is Armstrong or not. */
635
641
646 }
647
650 else
652
653 return 0;
654 }
655
659 */
660
661 /***************************************************************************************/
662
663 /* Q.18) Write a 'C' program to check whether a given year is leap year or not using
666
668 {
670
673
676 else
678
679 return 0;
680 }
681
localhost:64631 12/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
685 */
686
687 /***************************************************************************************/
688
689 /* Q.19) Write a 'C' program to check whether the enter number is palindrome or not. */
691
693 {
695
698
700
702 {
706 }
707
709
712
713 else
715
716 return 0;
717 }
718
723 */
724
725 /***************************************************************************************/
726
727 /* Q.20) ) Write a 'C' program to check whether a given year is leap year or not using
730
732 {
734
737
738 (year%4==0 && year%100!=0) ? printf("%d is Leap Year", year) : (year%400 ==0 ) ?
739 printf("%d is Leap Year", year) : printf("%d is not Leap Year", year);
740
741 return 0;
localhost:64631 13/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
742 }
743
747 */
748
749 /***************************************************************************************/
750
752 1
753 1 2
754 1 2 3
755 1 2 3 4
756 1 2 3 4 5 */
759 {
761
764
766 {
768 {
770 }
771 printf("\n");
772 }
773
774 return 0;
775 }
776
779 1
780 1 2
781 1 2 3
782 1 2 3 4
783 1 2 3 4 5
784 */
785
786 /***************************************************************************************/
787
788 /* Q.22) Write a 'C' program that takes a number as input from user and checks whether
791
793 {
795
798
localhost:64631 14/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
799 (num % 2 == 0)
802
803 return 0;
804 }
805
809 */
810
811 /***************************************************************************************/
812
813 /* Q.23) Write a 'C' program to check whether a given number is perfect number or not. */
815
817 {
819
822
824 {
825 if (num%i == 0)
827 }
828
831 else
833
834 return 0;
835 }
836
840 */
841
842 /***************************************************************************************/
843
844 /* Q.24) Write a 'C' program to display multiplication table of a given number. */
846
848 {
849 int n, i;
850
853
855 {
localhost:64631 15/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
856 printf("%d X %d = %d \n", n, i, n * i);
857 }
858
859 return 0;
860 }
861
864 11 X 1 = 11
865 11 X 2 = 22
866 11 X 3 = 33
867 11 X 4 = 44
868 11 X 5 = 55
869 11 X 6 = 66
870 11 X 7 = 77
871 11 X 8 = 88
872 11 X 9 = 99
873 11 X 10 = 110
874 */
875
876 /***************************************************************************************/
877
878 /* Q.25) Write a 'C' program to check whether a given character is VOWEL or CONSONANT
881
883 {
884 char p;
885
888
889 if ((p >= 'A' && p <= 'Z') || (p >= 'a' && p <= 'z'))
890 {
892 {
904 break;
905 default:
907 }
908 }
909 return 0;
910 }
911
localhost:64631 16/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
913 Enter a character : u
914 u is a VOWEL.
915 */
916
917 /***************************************************************************************/
918
919 /* Q.26) Write a 'C' program to check whether inputted character is digit or alphabet. */
921
923 {
924 char d;
925
928
930 {
932 }
933
934 else
935 {
937 }
938
939 return 0;
940 }
941
944 a is alphabet.
945 */
946
947 /***************************************************************************************/
948
949 /* Q.27) Write 'C' Program to check whether given character is vowel or consonant. */
951
953 {
954 char i;
955
958
959 if ((i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z'))
960 {
962 {
localhost:64631 17/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
970 case 'i':
974 break;
975 default:
977 }
978 }
979 return 0;
980 }
981
984 l is a consonant
985 */
986
987 /***************************************************************************************/
988
991
993 {
996
999
1001 {
1003 }
1004
1006
1007 return 0;
1008 }
1009
1013 */
1014
1015 /***************************************************************************************/
1016
1017 /* Q.29) Write 'C' Program to print the ASCII value of any given character. */
1019
1021 {
1022 char c;
1023
1026
localhost:64631 18/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1027 printf("ASCII value of %c = %d", c, c);
1028
1029 return 0;
1030 }
1034 */
1035
1036 /***************************************************************************************/
1037
1038 /* Q.30) Write a 'C' program to accept one number and to calculate sum of digits. */
1040
1042 {
1044
1047
1049 {
1050 m = n % 10;
1052 n = n / 10;
1053 }
1054
1056
1057 return 0;
1058 }
1059
1063 */
1064
1065 /***************************************************************************************/
1066
1067 /* Q.31) Write a 'C' Program to calculate the x to the power y without using standard
1068 function. */
1071
1073 {
1074 int i, x, y, z;
1075
1076 z = 1;
1077
1080
1083
localhost:64631 19/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1084 for (i=1; i<=y; i++)
1085 {
1086 z = z * x;
1087 }
1088
1090 getch();
1091 }
1092
1097 */
1098
1099 /***************************************************************************************/
1100
1101 /* Q.32) Write a 'C' Program to convert a given character into uppercase & vice versa. */
1104
1106 {
1108 int i;
1109
1111 gets(str);
1112
1114
1116 {
1119
1120 else
1121 ;
1122 }
1123
1125
1126 return 0;
1127 }
1128
1133 */
1134
1135 /***************************************************************************************/
1136
1138 * * * * *
1139 * * * *
1140 * * *
localhost:64631 20/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1141 * *
1142 * */
1144
1146 {
1148
1151
1153 {
1155 {
1157 }
1158 printf("\n");
1159 }
1160
1161 return 0;
1162 }
1163
1166 * * * * *
1167 * * * *
1168 * * *
1169 * *
1170 *
1171 */
1172
1173 /***************************************************************************************/
1174
1177
1179 {
1181
1184
1185 while (n != 0)
1186 {
1189 n /= 10;
1190 }
1192
1193 return 0;
1194 }
1195
localhost:64631 21/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1198 Reversed Number = 21
1199 */
1200
1201 /***************************************************************************************/
1202
1203 /* Q.35) Write a 'C' Program to check whether a given number is prime number or not. */
1205
1207 {
1209
1212
1214 {
1215 if (l % i == 0)
1216 {
1217 flag = 1;
1218 break;
1219 }
1220 }
1221
1222 if (flag == 0)
1224 else
1226
1227 return 0;
1228 }
1229
1233 */
1234
1235 /***************************************************************************************/
1236
1240
1242 {
1245
1247 scanf("%d",&x);
1248
1250 scanf("%d",&n);
1251
1253
localhost:64631 22/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1255 return 0;
1256 }
1257
1262 */
1263
1264 /***************************************************************************************/
1265
1266 /* Q.37) Write a 'C' Program to accept characters from the user and count total
1270
1272 {
1275
1277 gets(s);
1278
1280 {
1281 if ((s[i] >= 65 && s[i] <= 90) || (s[i] >= 97 && s[i] <= 122))
1282 alphabets++;
1283
1285 digits++;
1286
1287 else
1288 specialcharacters++;
1289 }
1290
1294
1295 return 0;
1296 }
1297
1300 Alphabets = 11
1301 Digits = 8
1303 */
1304
1305 /***************************************************************************************/
1306
1307 /* Q.38) Write a 'C' Program to accept a number and check if is divisible by 5 and 7. */
1309
1311 {
localhost:64631 23/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1313
1316
1317 if (num % 5 == 0)
1318 {
1320 }
1321
1323 {
1325 }
1326
1327 else
1328 {
1330 }
1331
1332 return 0;
1333 }
1334
1338 */
1339
1340 /***************************************************************************************/
1341
1342 /* Q.39) Write a 'C' Program to check whether a given character is a VOWEL or CONSONANT
1345
1347 {
1348 char p;
1349
1352
1353 if ((p >= 'A' && p <= 'Z') || (p >= 'a' && p <= 'z'))
1354 {
1356 {
1368 break;
localhost:64631 24/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1369 default:
1371 }
1372 }
1373 return 0;
1374 }
1375
1378 o is a VOWEL.
1379 */
1380
1381 /***************************************************************************************/
1382
1383 /* Q.40) Write a menu driven program, accept two numbers and perform following options:
1387
1389 {
1391
1394
1397
1399 {
1402 }
1403
1404 else
1405 {
1408 }
1410
1412 {
1416 }
1417
1420
1423 }
1424
localhost:64631 25/26
12/3/21, 8:45 PM c:\Users\admin\Assinment of C\Assignment.c
1430 */
localhost:64631 26/26