0% found this document useful (0 votes)
51 views80 pages

KPIT Yet To Onboard Assignment - Week - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views80 pages

KPIT Yet To Onboard Assignment - Week - 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 80

KPIT Yet to Onboard Assignment

Name - Nisheeth Kumar Tripathi


Registration Number – RA2011026010075
SRM Mail Id – [email protected]
Personal Mail Id – [email protected]
UG Course - B.Tech –Computer Science and Engineering with
specialization in Artificial Intelligence and Machine Learning
Phone Number – 9918065751
College – SRM University (KTR)

1
Chapter-4: More Complex Decision Making

Q1.

#include <stdio.h>

int main() {

float a, b, c;
printf("Enter the length of the first side: ");
scanf("%f", &a);
printf("Enter the length of the second side: ");
scanf("%f", &b);
printf("Enter the length of the third side: ");
scanf("%f", &c);

if (a + b <= c || a + c <= b || b + c <= a) {


printf("The given sides do not form a triangle.\n");
}
else {

if (a == b && b == c) {
printf("The triangle is an equilateral triangle.\n");
}
else if (a == b || b == c || a == c) {

if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a)) {
printf("The triangle is an isosceles and right-angled
triangle.\n");
}
else {
printf("The triangle is an isosceles triangle.\n");
}
}
else if ((a * a + b * b == c * c) ||
(a * a + c * c == b * b) ||
(b * b + c * c == a * a)) {

printf("The triangle is a right-angled triangle.\n");


} else {

printf("The triangle is a scalene triangle.\n");


2
}
}

return 0;
}

OUTPUT
Enter the length of the first side: 4
Enter the length of the second side: 6
Enter the length of the third side: 3
The triangle is a scalene triangle.
Enter the length of the first side: 5
Enter the length of the second side: 5
Enter the length of the third side: 5
The triangle is an equilateral triangle.

Q2

3
CODE
#include <stdio.h>
#include <cmath>

int main() {

int R, G, B;
float C, M, Y, K;
float White;

printf("Enter the Red (R) value (0-255): ");


scanf("%d", &R);
printf("Enter the Green (G) value (0-255): ");
scanf("%d", &G);
printf("Enter the Blue (B) value (0-255): ");
scanf("%d", &B);

if (R == 0 && G == 0 && B == 0) {
C = 0;
M = 0;
Y = 0;
K = 1;
}
else {

White = fmax(R / 255.0, fmax(G / 255.0, B / 255.0));

C = (White - R / 255.0) / White;


M = (White - G / 255.0) / White;
Y = (White - B / 255.0) / White;
K = 1 - White;
}

printf("CMYK values:\n");
printf("Cyan (C) = %.2f\n", C);
printf("Magenta (M) = %.2f\n", M);
printf("Yellow (Y) = %.2f\n", Y);
printf("Black (K) = %.2f\n", K);

return 0;
}

OUTPUT
Enter the Red (R) value (0-255): 56

4
Enter the Green (G) value (0-255): 90
Enter the Blue (B) value (0-255): 76
CMYK values:
Cyan (C) = 0.38
Magenta (M) = 0.00
Yellow (Y) = 0.16
Black (K) = 0.65

Q3

5
CODE
#include <stdio.h>

int main() {

float hardness, carbonContent, tensileStrength;


int grade;

printf("Enter the hardness of the steel: ");


scanf("%f", &hardness);
printf("Enter the carbon content of the steel: ");
scanf("%f", &carbonContent);
printf("Enter the tensile strength of the steel: ");
scanf("%f", &tensileStrength);

if (hardness > 50 && carbonContent < 0.7 && tensileStrength > 5600)
{
grade = 10;
}
else if (hardness > 50 && carbonContent < 0.7) {
grade = 9;
}
else if (carbonContent < 0.7 && tensileStrength > 5600) {
grade = 8;
}
else if (hardness > 50 && tensileStrength > 5600) {
grade = 7;
}
else if (hardness > 50 || carbonContent < 0.7 || tensileStrength >
5600) {
grade = 6;
}
else {
grade = 5;
}

printf("The grade of the steel is: %d\n", grade);

return 0;
}

OUTPUT
Enter the hardness of the steel: 50
Enter the carbon content of the steel: 0.4
Enter the tensile strength of the steel: 6000

6
The grade of the steel is: 8

Q4

CODE
#include <stdio.h>

int main() {

float weight, height, bmi;

printf("Enter weight (in kg): ");


scanf("%f", &weight);
printf("Enter height (in meters): ");
scanf("%f", &height);

bmi = weight / (height * height);

printf("Your BMI is: %.2f\n", bmi);


printf("BMI Category: ");

if (bmi < 15) {


printf("Starvation\n");
} else if (bmi >= 15 && bmi <= 17.5) {
printf("Anorexic\n");
7
} else if (bmi > 17.5 && bmi <= 18.5) {
printf("Underweight\n");
} else if (bmi > 18.5 && bmi <= 24.9) {
printf("Ideal\n");
} else if (bmi >= 25 && bmi <= 29.9) {
printf("Overweight\n");
} else if (bmi >= 30 && bmi <= 39.9) {
printf("Obese\n");
} else if (bmi >= 40) {
printf("Morbidly Obese\n");
}

return 0;
}

OUTPUT
Enter weight (in kg): 60.20
Enter height (in meters): 1.78
Your BMI is: 19.00
BMI Category: Ideal

8
Chapter-5: Loop Control Instruction

Q1.

CODE
#include <stdio.h>

int main() {

int ascii_value = 0;

printf("ASCII Value\tCharacter\n");
printf("--------------------------\n");

while (ascii_value <= 255) {


printf("%d\t\t%c\n", ascii_value, ascii_value);
ascii_value++;
}

return 0;
}

OUTPUT
ASCII Value Character
--------------------------
0
1 ☺
2 ☻
3 ♥
4 ♦
5 ♣
6 ♠
7
8
9
9
10

11

12

13
14
15
16 ►
17 ◄
18 ↕
19 ‼
20 ¶
21 §
22 ▬
23 ↨
24 ↑
25 ↓
26 →
27

8 ∟
29 ↔
30 ▲
31 ▼
32
33 !
34 "
35 #
36 $
10
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
11
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
12
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127
128 Ç
129 ü
130 é
131 â
132 ä
13
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 ñ
14
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 ─
15
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 Σ
16
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

Q2

17
CODE
#include <stdio.h>

int main() {
int i, copy, remainder, sum;

printf("Armstrong numbers between 1 and 500 are:\n");

for (i = 1; i <= 500; i++) {


copy = i;
sum = 0;

while (copy != 0) {
remainder = copy % 10;
sum += remainder * remainder * remainder;
copy /= 10;
}

if (sum == i) {
printf("%d\n", i);
}
}

return 0;
}

OUTPUT
Armstrong numbers between 1 and 500 are:
1
153
370
371
407

18
Q3

CODE
#include<stdio.h>
#include<conio.h>
int main()
{
int match_sticks = 21, user_choice, computer_choice;
while(match_sticks>=1)
{
printf("Total Match Sticks: %d\n", match_sticks);
printf("Pick up the match sticks between (1 to 4): ");
scanf("%d", &user_choice);

if(user_choice>4)
{
printf("Invalid Entry");
break;
}

computer_choice = 5 - user_choice;

printf("Computer picks up the %d match sticks.\n",


computer_choice);
match_sticks = match_sticks-user_choice-computer_choice;
if(match_sticks==1)
{
printf("\nComputer Wins.");
break;
19
}
}
return(0);
}

OUTPUT
Total Match Sticks: 21
Pick up the match sticks between (1 to 4): 3
Computer picks up the 2 match sticks.
Total Match Sticks: 16
Pick up the match sticks between (1 to 4): 2
Computer picks up the 3 match sticks.
Total Match Sticks: 11
Pick up the match sticks between (1 to 4): 4
Computer picks up the 1 match sticks.
Total Match Sticks: 6
Pick up the match sticks between (1 to 4): 4
Computer picks up the 1 match sticks.
Computer Wins.

Q4

CODE
#include <stdio.h>

int main() {
int number, positiveCount = 0, negativeCount = 0, zeroCount = 0;
char choice;

do {

printf("Enter a number: ");


scanf("%d", &number);

if (number > 0) {
positiveCount++;
} else if (number < 0) {

20
negativeCount++;
} else {
zeroCount++;
}

printf("Do you want to enter another number? (y/n): ");


scanf(" %c", &choice);

} while (choice == 'y' || choice == 'Y');

printf("\nCount of positive numbers: %d\n", positiveCount);


printf("Count of negative numbers: %d\n", negativeCount);
printf("Count of zeros: %d\n", zeroCount);

return 0;
}

OUTPUT
Enter a number: 324
Do you want to enter another number? (y/n): y
Enter a number: 455
Do you want to enter another number? (y/n): y
Enter a number: -47
Do you want to enter another number? (y/n): y
Enter a number: 0
Do you want to enter another number? (y/n): y
Enter a number: 0
Do you want to enter another number? (y/n): n

Count of positive numbers: 2


Count of negative numbers: 1
Count of zeros: 2

Q5

21
CODE
#include <stdio.h>

int main() {
int decimal, quotient, octal, i, j;

printf("Enter an integer: ");


scanf("%d", &decimal);

quotient = decimal;
octal = 0;
i = 1;

while (quotient != 0) {
octal += (quotient % 8) * i;
i *= 10;
quotient /= 8;
}

printf("Octal equivalent: %d\n", octal);

return 0;
}

OUTPUT
Enter an integer: 4567
Octal equivalent: 10727

Q6

CODE
#include <stdio.h>

int main() {
int n, i;
22
int smallest, largest, num;

printf("Enter the number of elements: ");


scanf("%d", &n);

printf("Enter %d numbers:\n", n);

scanf("%d", &num);
smallest = largest = num;

for (i = 1; i < n; i++) {


scanf("%d", &num);
if (num < smallest) {
smallest = num;
}
if (num > largest) {
largest = num;
}
}

printf("Range of the numbers: %d\n", largest - smallest);

return 0;
}

OUTPUT
Enter the number of elements: 5
Enter 5 numbers:
342
675
45435
6756
3
Range of the numbers: 45432

23
Chapter-6: More Complex Repetitions

Q1.

CODE
#include <stdio.h>

int main() {

int number, i;

printf("Enter the number : ");


scanf("%d", &number);

for (i = 1; i <= 10; ++i) {


printf("%d * %d = %d\n", number, i, number * i);
}

return 0;
}
24
OUTPUT
Enter the number : 5
5*1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Q2

CODE
#include <stdio.h>

int main() {
double y, x, i;

printf("y\t\tx\t\ti\n");
printf("-----------------------------\n");

for (y = 1; y <= 6; y++) {


for (x = 5.5; x <= 12.5; x += 0.5) {
i = 2 + (y + 0.5 * x);
printf("%.1lf\t\t%.1lf\t\t%.2lf\n", y, x, i);
25
}
}

return 0;
}

OUTPUT
y x i
-----------------------------
1.0 5.5 5.75
1.0 6.0 6.00
1.0 6.5 6.25
1.0 7.0 6.50
1.0 7.5 6.75
1.0 8.0 7.00
1.0 8.5 7.25
1.0 9.0 7.50
1.0 9.5 7.75
1.0 10.0 8.00
1.0 10.5 8.25
1.0 11.0 8.50
1.0 11.5 8.75
1.0 12.0 9.00
1.0 12.5 9.25
2.0 5.5 6.75
2.0 6.0 7.00
2.0 6.5 7.25
2.0 7.0 7.50
2.0 7.5 7.75
2.0 8.0 8.00
2.0 8.5 8.25
2.0 9.0 8.50
2.0 9.5 8.75

26
2.0 10.0 9.00
2.0 10.5 9.25
2.0 11.0 9.50
2.0 11.5 9.75
2.0 12.0 10.00
2.0 12.5 10.25
3.0 5.5 7.75
3.0 6.0 8.00
3.0 6.5 8.25
3.0 7.0 8.50
3.0 7.5 8.75
3.0 8.0 9.00
3.0 8.5 9.25
3.0 9.0 9.50
3.0 9.5 9.75
3.0 10.0 10.00
3.0 10.5 10.25
3.0 11.0 10.50
3.0 11.5 10.75
3.0 12.0 11.00
3.0 12.5 11.25
4.0 5.5 8.75
4.0 6.0 9.00
4.0 6.5 9.25
4.0 7.0 9.50
4.0 7.5 9.75
4.0 8.0 10.00
4.0 8.5 10.25
4.0 9.0 10.50
4.0 9.5 10.75
4.0 10.0 11.00
4.0 10.5 11.25
27
4.0 11.0 11.50
4.0 11.5 11.75
4.0 12.0 12.00
4.0 12.5 12.25
5.0 5.5 9.75
5.0 6.0 10.00
5.0 6.5 10.25
5.0 7.0 10.50
5.0 7.5 10.75
5.0 8.0 11.00
5.0 8.5 11.25
5.0 9.0 11.50
5.0 9.5 11.75
5.0 10.0 12.00
5.0 10.5 12.25
5.0 11.0 12.50
5.0 11.5 12.75
5.0 12.0 13.00
5.0 12.5 13.25
6.0 5.5 10.75
6.0 6.0 11.00
6.0 6.5 11.25
6.0 7.0 11.50
6.0 7.5 11.75
6.0 8.0 12.00
6.0 8.5 12.25
6.0 9.0 12.50
6.0 9.5 12.75
6.0 10.0 13.00
6.0 10.5 13.25
6.0 11.0 13.50
6.0 11.5 13.75
28
6.0 12.0 14.00
6.0 12.5 14.25

Q3

CODE
#include <stdio.h>
#include <math.h>

int main() {
double p, r, a;
int n, q, i;

for(i = 1; i <= 10; i++) {


printf("Enter principal (p), rate of interest (r), number of
years (n), and number of times interest is compounded per year (q) for
set %d: ", i);
scanf("%lf %lf %d %d", &p, &r, &n, &q);

a = p * pow((1 + r/(100*q)), n*q);

printf("The amount for set %d is: %.2lf\n", i, a);


}

return 0;
}

OUTPUT
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 1: 658
10
2

29
2
The amount for set 1 is: 799.80
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 2: 9834
21
4
6
The amount for set 2 is: 22454.25
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 3: 34
56
3
4
The amount for set 3 is: 163.81
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 4: 2643
4
5
6
The amount for set 4 is: 3226.03
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 5: 453535
45
56
58
The amount for set 5 is: 36190455769839944.00
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 6: 545
435
56
56
The amount for set 6 is:
419446363842950700000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000.00

30
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 7: 54656
3

34
43
The amount for set 7 is: 151517.84
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 8: 656
54
4
4
The amount for set 8 is: 4975.51
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 9:
546346
56
5
4
The amount for set 9 is: 7508700.72
Enter principal (p), rate of interest (r), number of years (n), and number of times interest is
compounded per year (q) for set 10: 777567
456
10
10
The amount for set 10 is: 16101833017536977000000.00
Q4

31
CODE
#include <stdio.h>
#include <math.h>

int main() {
double x,y, term, sum = 0;

int i;

printf("Enter the value of x: ");


scanf("%lf", &x);
term = (x-1)/x;

for(i = 2; i <= 7; i++) {

y = pow(term,i);

sum = sum+0.5*y;

}
sum=sum+term;

printf("Sum of the first seven terms: %.3lf\n", sum);

return 0;
}

OUTPUT
Enter the value of x: 4
Sum of the first seven terms: 1.675

Q5

CODE
#include <stdio.h>

int main() {
int a, b, c;

for (a = 1; a <= 30; a++) {


for (b = a; b <= 30; b++) {
for (c = b; c <= 30; c++) {
32
if (a*a + b*b == c*c || b*b + c*c == a*a || a*a + c*c
== b*b) {
printf("%d %d %d\n", a, b, c);
}
}
}
}

return 0;
}

OUTPUT
345
5 12 13
6 8 10
7 24 25
8 15 17
9 12 15
10 24 26
12 16 20
15 20 25
18 24 30
20 21 29

Q6

CODE
#include <stdio.h>

int main() {
int population = 100000; // Initial population
double growth_rate = 0.10; // 10% growth rate

printf("Year\tPopulation\n");
printf("----\t----------\n");
33
for (int year = 0; year <= 9; year++) {
population += population * growth_rate;
printf("%d\t%lu\n", year, population);
}

return 0;
}

OUTPUT
Year Population
---- ----------
0 110000
1 121000
2 133100
3 146410
4 161051
5 177156
6 194871
7 214358
8 235793
9 259372

Q7

CODE
#include <stdio.h>

int main() {
int i, j, k, l;
int cube1, cube2;

for (i = 1; i <= 100; i++) {


for (j = i; j <= 100; j++) {

34
cube1 = i * i * i + j * j * j;

for (k = i + 1; k <= 100; k++) {


for (l = k; l <= 100; l++) {
cube2 = k * k * k + l * l * l;

if (cube1 == cube2) {
printf("Ramanujan number: %d\n", cube1);
}
}
}
}
}

return 0;
}

OUTPUT
Ramanujan number: 1729
Ramanujan number: 4104
Ramanujan number: 13832
Ramanujan number: 39312
Ramanujan number: 704977
Ramanujan number: 46683
Ramanujan number: 216027
Ramanujan number: 32832
Ramanujan number: 110656
Ramanujan number: 314496
Ramanujan number: 216125
Ramanujan number: 439101
Ramanujan number: 110808
Ramanujan number: 373464
Ramanujan number: 593047
Ramanujan number: 149389
Ramanujan number: 262656
Ramanujan number: 885248
Ramanujan number: 40033

35
Ramanujan number: 195841
Ramanujan number: 20683
Ramanujan number: 513000
Ramanujan number: 805688
Ramanujan number: 65728
Ramanujan number: 134379
Ramanujan number: 886464
Ramanujan number: 515375
Ramanujan number: 64232
Ramanujan number: 171288
Ramanujan number: 443889
Ramanujan number: 320264
Ramanujan number: 165464
Ramanujan number: 920673
Ramanujan number: 842751
Ramanujan number: 525824
Ramanujan number: 955016
Ramanujan number: 994688
Ramanujan number: 327763
Ramanujan number: 558441
Ramanujan number: 513856
Ramanujan number: 984067
Ramanujan number: 402597
Ramanujan number: 1016496
Ramanujan number: 1009736
Ramanujan number: 684019

Q8

CODE

36
#include <stdio.h>

int main() {
for (int hour = 0; hour < 24; hour++) {
if (hour == 0) {
printf("12 Midnight\n");
} else if (hour == 12) {
printf("12 Noon\n");
} else if (hour < 12) {
printf("%d : 00 AM\n", hour);
} else {
printf("%d : 00 PM\n", hour % 12);
}
}
return 0;
}

OUTPUT
12 Midnight
1 : 00 AM
2 : 00 AM
3 : 00 AM
4 : 00 AM
5 : 00 AM
6 : 00 AM
7 : 00 AM
8 : 00 AM
9 : 00 AM
10 : 00 AM
11 : 00 AM
12 Noon
1 : 00 PM
2 : 00 PM
3 : 00 PM
4 : 00 PM
5 : 00 PM
6 : 00 PM

37
7 : 00 PM
8 : 00 PM
9 : 00 PM
10 : 00 PM
11 : 00 PM

Q9

CODE
#include <stdio.h>

int main() {
int num = 1;

for (int row = 1; row <= 4; row++) {

for (int space = 1; space <= 4 - row; space++) {


printf(" ");
}

// Loop for each column in the row


for (int col = 1; col <= row; col++) {
printf("%d ", num);
num++;
}
printf("\n");
}

return 0;
}
38
OUTPUT
1
23
456
7 8 9 10

39
Chapter-7: Case Control Instruction

Q1

CODE
#include <stdio.h>

int main() {
int choice, num,check=1;
long long int fact =1;

while(1){
printf("Menu:\n");
printf("1. Factorial of a number\n");
printf("2. Prime or not\n");
printf("3. Odd or Even\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
printf("Enter a positive integer: ");
scanf("%d", &num);
if (num == 0 || num == 1) {
return 1;
}
int i;
for(i=1; i<=num;i++)
{
fact = fact*i;
}
printf("Factorial of %d = %d\n", num, fact);
break;
case 2:
printf("Enter an integer: ");

40
scanf("%d", &num);
if (num <= 1) {
printf("%d is not a prime number.\n", num);
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
check=0;

}
}
if (check==1) {
printf("%d is a prime number.\n", num);
}
else
{
printf("%d is not a prime number.\n", num);
}
break;
case 3:
printf("Enter the integer: ");
scanf("%d", &num);
if(num%2==0)
{
printf("%d is an even number.\n", num);

}
else
{
printf("%d is an odd number.\n", num);
}
break;
case 4:
printf("Exiting the program. Goodbye!\n");
return 0;
break;
default:
printf("Invalid choice. Please select 1, 2, or 3.\n");
}
}

OUTPUT
Menu:

1. Factorial of a number

2. Prime or not

3. Odd or Even

4. Exit

Enter your choice: 27

Invalid choice. Please select 1, 2, or 3.

Menu:
41
1. Factorial of a number

2. Prime or not

3. Odd or Even

4. Exit

Enter your choice: 1

Enter a positive integer: 19

Factorial of 19 = 109641728

Menu:

1. Factorial of a number

2. Prime or not

3. Odd or Even

4. Exit

Enter your choice: 2

Enter an integer: 352

352 is not a prime number.

Menu:

1. Factorial of a number

2. Prime or not

3. Odd or Even

4. Exit

Enter your choice: 3

Enter the integer: 45

45 is an odd number.

Menu:

1. Factorial of a number

2. Prime or not

3. Odd or Even

4. Exit

Enter your choice: 4

Exiting the program. Goodbye!

42
Chapter-8: Functions

Q1

CODE
#include <stdio.h>

int leap_year(int year) {


if (year % 400 == 0) {
return 1;
} else if (year % 100 == 0) {
return 0;
} else if (year % 4 == 0) {
return 1;
} else {
return 0;
}
}

int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);

if (leap_year(year)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}

return 0;
}

OUTPUT
Enter a year: 2024

43
2024 is a leap year.

Q2

CODE
#include <stdio.h>

void prime_factors(int n) {

while (n % 2 == 0) {
printf("%d ", 2);
n = n / 2;
}

for (int i = 3; i * i <= n; i += 2) {

while (n % i == 0) {
printf("%d ", i);
n = n / i;
}
}

if (n > 2) {
printf("%d ", n);
}
}

int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);

printf("Prime factors of %d are: ", n);


prime_factors(n);
printf("\n");

return 0;
}

OUTPUT
44
Enter a positive integer: 428
Prime factors of 428 are: 2 2 107
Chapter-9: Pointers

Q1

CODE
#include <stdio.h>

void circular_shift_right(int *x, int *y, int *z) {


int temp = *z;
*z = *y;
*y = *x;
*x = temp;
}

int main() {
int a, b, c;

printf("Enter values for a, b, and c: ");


scanf("%d %d %d", &a, &b, &c);

printf("Before circular shift: a = %d, b = %d, c = %d\n", a,


b, c);

circular_shift_right(&a, &b, &c);

printf("After circular shift: a = %d, b = %d, c = %d\n", a,


b, c);

return 0;
}

OUTPUT
Enter values for a, b, and c: 43
45
35
56
Before circular shift: a = 43, b = 35, c = 56
After circular shift: a = 56, b = 43, c = 35

Q2

CODE
#include <stdio.h>

void convert_weight(double *kg, double *grams, double *tons,


double *pounds) {
*grams = *kg * 1000.0;
*tons = *kg * 0.001;
*pounds = *kg * 2.20462;
}

int main() {
double kg, grams, tons, pounds;

printf("Enter weight in kilograms: ");


scanf("%lf", &kg);

convert_weight(&kg, &grams, &tons, &pounds);

printf("Weight in grams: %.2lf g\n", grams);


printf("Weight in tons: %.2lf tons\n", tons);
printf("Weight in pounds: %.2lf lbs\n", pounds);

return 0;
}

OUTPUT
46
Enter weight in kilograms: 60.20
Weight in grams: 60200.00 g
Weight in tons: 0.06 tons
Weight in pounds: 132.72 lbs

Q3

CODE
#include <stdio.h>
#include <math.h>

void distance(double x1, double y1, double x2, double y2, double
*dist) {
*dist = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

void area_of_triangle(double x1, double y1, double x2, double y2,


double x3, double y3, double *area) {
*area = fabs((x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)) /
2.0);
}

void is_point_inside_triangle(double x1, double y1, double x2,


double y2, double x3, double y3, double x, double y, int *inside)
{
double area_ABC, area_PAB, area_PBC, area_PCA;

area_of_triangle(x1, y1, x2, y2, x3, y3, &area_ABC);

area_of_triangle(x, y, x1, y1, x2, y2, &area_PAB);


area_of_triangle(x, y, x2, y2, x3, y3, &area_PBC);

47
area_of_triangle(x, y, x3, y3, x1, y1, &area_PCA);

*inside = (fabs(area_ABC - (area_PAB + area_PBC + area_PCA))


< 1e-9) ? 1 : 0;
}

int main() {
double x1, y1, x2, y2, x3, y3;
double x, y;
int inside;

printf("Enter the coordinates of the first vertex (x1, y1):


");
scanf("%lf %lf", &x1, &y1);
printf("Enter the coordinates of the second vertex (x2, y2):
");
scanf("%lf %lf", &x2, &y2);
printf("Enter the coordinates of the third vertex (x3, y3):
");
scanf("%lf %lf", &x3, &y3);

printf("Enter the coordinates of the point (x, y): ");


scanf("%lf %lf", &x, &y);

is_point_inside_triangle(x1, y1, x2, y2, x3, y3, x, y,


&inside);

if (inside) {
printf("The point (%.2lf, %.2lf) lies inside the
triangle.\n", x, y);
} else {
printf("The point (%.2lf, %.2lf) does not lie inside the
triangle.\n", x, y);
}

return 0;
}

OUTPUT
Enter the coordinates of the first vertex (x1, y1): 6
7
Enter the coordinates of the second vertex (x2, y2): 2

48
1
Enter the coordinates of the third vertex (x3, y3): 3
4
Enter the coordinates of the point (x, y): 2
3
The point (2.00, 3.00) does not lie inside the triangle.

Chapter-10: Recursion

Q1

CODE
#include <stdio.h>

void binary_recursive(int n) {
if (n == 0) {
printf("0");
return;
}
binary_recursive(n / 2);
printf("%d", n % 2);
}

int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d", &n);

printf("Binary equivalent : ");


binary_recursive(n);
printf("\n");

return 0;
49
}

OUTPUT
Enter a positive integer: 647
Binary equivalent : 01010000111

Q2

CODE
#include <stdio.h>

int sum_of_natural_numbers(int n) {

if(n==1)
{
return 1;
}
else{
return n+ sum_of_natural_numbers(n-1);
}
}

int main() {
int n = 50;
int sum = sum_of_natural_numbers(n);

printf("The sum of the first %d natural numbers is: %d\n", n,


sum);

return 0;
}

OUTPUT
50
The sum of the first 50 natural numbers is: 1275

Q3

CODE
#include <stdio.h>

void tower_of_hanoi(int n, char from_peg, char to_peg, char


aux_peg) {

if (n == 1) {
printf("Move disk 1 from peg %c to peg %c\n", from_peg,
to_peg);
return;
}

51
tower_of_hanoi(n - 1, from_peg, aux_peg, to_peg);

printf("Move disk %d from peg %c to peg %c\n", n, from_peg,


to_peg);

tower_of_hanoi(n - 1, aux_peg, to_peg, from_peg);


}

int main() {
int n ;
printf("Enter the number of disk in the first peg: ");
scanf("%d",&n);

printf("The sequence of moves to solve the Tower of Hanoi


with %d disks is:\n", n);
tower_of_hanoi(n, 'A', 'C', 'B');

return 0;
}

OUTPUT
Enter the number of disk in the first peg: 4
The sequence of moves to solve the Tower of Hanoi with 4 disks is:
Move disk 1 from peg A to peg B
Move disk 2 from peg A to peg C
Move disk 1 from peg B to peg C
Move disk 3 from peg A to peg B
Move disk 1 from peg C to peg A
Move disk 2 from peg C to peg B
Move disk 1 from peg A to peg B
Move disk 4 from peg A to peg C
Move disk 1 from peg B to peg C
Move disk 2 from peg B to peg A

52
Move disk 1 from peg C to peg A
Move disk 3 from peg B to peg C
Move disk 1 from peg A to peg B
Move disk 2 from peg A to peg C
Move disk 1 from peg B to peg C

Chapter-12: C Preprocessor

Q1

CODE
#include <stdio.h>

#define SQUARE(x) (x * x)
#define SUM(a, b) ((a) + (b))

int main() {
int x = 5;
int y = 10;

printf("Square of x: %d\n", SQUARE(x));


printf("Sum of x and y: %d\n", SUM(x, y));

return 0;
}

Macro Expansion
# 6 "question1.cpp"
int main() {
int x = 5;
int y = 10;

printf("Square of x: %d\n", (x * x));

53
printf("Sum of x and y: %d\n", ((x) + (y)));

return 0;
}

Q2

CODE
#include <stdio.h>

#define ARITHMETIC_MEAN(a, b) (((a) + (b)) / 2.0)


#define ABSOLUTE_VALUE(x) ((x) < 0 ? -(x) : (x))
#define TO_LOWERCASE(c) (((c) >= 'A' && (c) <= 'Z') ? ((c) + 'a' - 'A')
: (c))
#define BIGGEST_OF_THREE(a, b, c) (((a) > (b) && (a) > (c)) ? (a) :
((b) > (c) ? (b) : (c)))

int main() {
int a = 10, b = 20, c = -30;
char upper = 'G';

printf("Arithmetic mean of %d and %d is %.2f\n", a, b,


ARITHMETIC_MEAN(a, b));

printf("Absolute value of %d is %d\n", c, ABSOLUTE_VALUE(c));

printf("Lowercase of %c is %c\n", upper, TO_LOWERCASE(upper));

54
printf("Biggest of %d, %d, and %d is %d\n", a, b, c,
BIGGEST_OF_THREE(a, b, ABSOLUTE_VALUE(c)));

return 0;
}

OUTPUT
Arithmetic mean of 10 and 20 is 15.00
Absolute value of -30 is 30
Lowercase of G is g
Biggest of 10, 20, and -30 is 30

Chapter-13: Arrays

Q1

CODE
#include <stdio.h>

int main() {
int numbers[25];
int positive_count = 0, negative_count = 0;
int even_count = 0, odd_count = 0;

printf("Enter 25 numbers:\n");
for (int i = 0; i < 25; i++) {
scanf("%d", &numbers[i]);
}

for (int i = 0; i < 25; i++) {


if (numbers[i] > 0) {
positive_count++;
} else if (numbers[i] < 0) {
negative_count++;
}

55
if (numbers[i] % 2 == 0) {
even_count++;
} else {
odd_count++;
}
}

printf("Number of positive numbers: %d\n", positive_count);


printf("Number of negative numbers: %d\n", negative_count);
printf("Number of even numbers: %d\n", even_count);
printf("Number of odd numbers: %d\n", odd_count);

return 0;
}

OUTPUT
4
5355
5345
-55
654353
65
3453534534
3453
65
343456
555
6
3456
536
5
3656
56
345
5
634
5346
57
635
557858
7878
76
Number of positive numbers: 24
Number of negative numbers: 1
Number of even numbers: 12
Number of odd numbers: 13

Q2

CODE
#include <stdio.h>

int main() {
int n;

printf("Enter the number of elements in the array: ");


scanf("%d", &n);

int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int is_symmetric = 1;
57
for (int i = 0; i < n / 2; i++) {
if (arr[i] != arr[n - 1 - i]) {
is_symmetric = 0;
break;
}
}

if (is_symmetric) {
printf("The array satisfies the condition.\n");
} else {
printf("The array does not satisfy the condition.\n");
}

return 0;
}

OUTPUT
Enter the number of elements in the array: 6
Enter 6 elements:
1
2
3
3
2
1
The array satisfies the condition.

Q3

CODE
#include <stdio.h>

int main() {
58
int arr[25];
int *ptr = arr;

printf("Enter 25 integers:\n");
for (int i = 0; i < 25; i++) {
scanf("%d", ptr + i);
}

int smallest = *ptr;

for (int i = 1; i < 25; i++) {


if (*(ptr + i) < smallest) {
smallest = *(ptr + i);
}
}

printf("The smallest number in the array is: %d\n", smallest);

return 0;
}

OUTPUT
Enter 25 integers:
3
43
53
35768
43546
34
65
35
4
343
656
59
45
3565
78
6
45
578
767567
66
4
6767
45
65
64
54
The smallest number in the array is: 3

Q4

60
CODE
#include <stdio.h>

void insertionSort(int arr[], int n) {


for (int i = 1; i < n; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}

void printArray(int arr[], int n) {


for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}

int main() {
int arr[25];
printf("Enter 25 integers:\n");
for (int i = 0; i < 25; i++) {
scanf("%d", &arr[i]);
}
insertionSort(arr, 25);
printf("Sorted array:\n");
printArray(arr, 25);

return 0;
}

OUTPUT
Enter 25 integers:
654643
6757
36
5568

61
768
6757
798
5
65
6
68
5347
78
6
58
5
587856645
4769
86
767
97
57
8
66
8
Sorted array:
5 5 6 6 8 8 36 57 58 65 66 68 78 86 97 767 768 798 4769 5347 5568
6757 6757 654643 587856645

Q5

62
CODE
#include <stdio.h>

void modify(int arr[], int size) {


for (int i = 0; i < size; i++) {
arr[i] *= 3;
}
}

int main() {
int arr[10];

printf("Original array:\n");
for (int i = 0; i < 10; i++) {
arr[i] = i + 1;
printf("%d ", arr[i]);
}
printf("\n");

modify(arr, 10);

printf("Modified array:\n");
for (int i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
printf("\n");

return 0;
}

63
OUTPUT
Original array:
1 2 3 4 5 6 7 8 9 10
Modified array:
3 6 9 12 15 18 21 24 27 30

Q6

CODE
#include <stdio.h>
#include <math.h>

double calculateMean(int data[], int size) {


double sum = 0.0;
for (int i = 0; i < size; i++) {
sum += data[i];
}
return sum / size;
}

double calculateStandardDeviation(int data[], int size, double mean) {


double sumSquaredDifferences = 0.0;
for (int i = 0; i < size; i++) {
sumSquaredDifferences += pow(data[i] - mean, 2);
}
return sqrt(sumSquaredDifferences / size);
}

int main() {
int data[] = {-6, -12, 8, 13, 11, 6, 7, 2, -6, -9, -10, 11, 10, 9,
2};
int size = sizeof(data) / sizeof(data[0]);
64
double mean = calculateMean(data, size);

double standardDeviation = calculateStandardDeviation(data, size,


mean);

printf("Mean: %.2f\n", mean);


printf("Standard Deviation: %.2f\n", standardDeviation);

return 0;
}

OUTPUT
Mean: 2.40
Standard Deviation: 8.40

Q7

CODE
#include <stdio.h>
#include <math.h>
65
int main() {

double a[6] = {137.4, 155.2, 149.3, 160, 155.6, 149.7};


double b[6] = {80.9, 92.62, 97.93, 100.25, 68.95, 120};
double angle[6] = {0.78, 0.89, 1.0, 0.35, 1.25, 1.75};

for (int i = 0; i < 6; ++i) {


double area = 0.5 * a[i] * b[i] * sin(angle[i]);
printf("Plot No. %d: Area = %.2lf square units\n", i + 1,
area);
}

return 0;
}

OUTPUT
Plot No. 1: Area = 3908.71 square units
Plot No. 2: Area = 5585.06 square units
Plot No. 3: Area = 6151.55 square units
Plot No. 4: Area = 2750.04 square units
Plot No. 5: Area = 5090.65 square units
Plot No. 6: Area = 8838.16 square units

Q8

66
CODE
#include <stdio.h>
#include <math.h>

int main() {
double x[] = {34.22,39.87,41.85,43.23,40.06,53.29,53.29,54.14,
49.12, 40.71, 55.15};
double y[] = {102.43,100.93,97.43,97.81,98.32,98.32,100.07,97.08,
91.55, 94.89, 94.65};
int n = 4;

double sum_x = 0, sum_y = 0, sum_xy = 0, sum_x_squared = 0,


sum_y_squared = 0;
for (int i = 0; i < n; ++i) {
sum_x += x[i];
sum_y += y[i];
sum_xy += x[i] * y[i];
sum_x_squared += x[i] * x[i];
sum_y_squared += y[i] * y[i];
}

67
double numerator = n * sum_xy - sum_x * sum_y;
double denominator = sqrt((n * sum_x_squared - sum_x * sum_x) * (n
* sum_y_squared - sum_y * sum_y));
double r = numerator / denominator;

printf("Correlation coefficient (r) = %.4lf\n", r);

return 0;
}

OUTPUT
Correlation coefficient (r) = -0.9108

Q9

CODE
#include <stdio.h>
#include <math.h>

int main() {
int numPoints = 10;
double x[numPoints], y[numPoints];
double totalDistance = 0.0;

printf("Enter the X and Y coordinates of %d points:\n", numPoints);


for (int i = 0; i < numPoints; ++i) {
printf("Point %d (X Y): ", i + 1);
scanf("%lf %lf", &x[i], &y[i]);
}

for (int i = 0; i < numPoints - 1; ++i) {


double dx = x[i + 1] - x[i];
double dy = y[i + 1] - y[i];
double distance = sqrt(dx * dx + dy * dy);
totalDistance += distance;
}

68
printf("Total distance between the first and last point: %.2lf\n",
totalDistance);

return 0;
}

OUTPUT
Enter the X and Y coordinates of 10 points:
Point 1 (X Y): 4
5
Point 2 (X Y): 2
3
Point 3 (X Y): 5
8
Point 4 (X Y): 4
9
Point 5 (X Y): 23
67
Point 6 (X Y): 1
2
Point 7 (X Y): 0
1
Point 8 (X Y): 8
8
Point 9 (X Y): 3
3
Point 10 (X Y): 5
5
69
Total distance between the first and last point: 161.67

Q10

CODE
#include <stdio.h>
#include <stdbool.h>

#define MAX_SIZE 10

char dequeue[MAX_SIZE];
int left = -1;
int right = -1;

bool isEmpty() {
return (left == -1 && right == -1);
}

bool isFull() {
return (right == MAX_SIZE - 1);
}

void insertLeft(char item) {


if (isFull()) {
printf("Dequeue is full. Cannot insert.\n");
return;
}
if (isEmpty()) {
left = right = 0;
} else {
left--;
}
dequeue[left] = item;
}

void insertRight(char item) {


70
if (isFull()) {
printf("Dequeue is full. Cannot insert.\n");
return;
}
if (isEmpty()) {
left = right = 0;
} else {
right++;
}
dequeue[right] = item;
}

char retrieveLeft() {
if (isEmpty()) {
printf("Dequeue is empty. Cannot retrieve.\n");
return '\0';
}
char item = dequeue[left];
if (left == right) {
left = right = -1;
} else {
left++;
}
return item;
}

char retrieveRight() {
if (isEmpty()) {
printf("Dequeue is empty. Cannot retrieve.\n");
return '\0';
}
char item = dequeue[right];
if (left == right) {
left = right = -1;
} else {
right--;
}
return item;
}

int main() {

insertLeft('A');
insertRight('B');
insertLeft('C');
insertRight('D');

printf("Retrieve from left: %c\n", retrieveLeft());


printf("Retrieve from right: %c\n", retrieveRight());
71
return 0;
}

OUTPUT
Retrieve from left: C
Retrieve from right: D

Chapter-14: Multidimensional Array


Q1

CODE
#include <stdio.h>

int main() {
int threed[3][2][3] = {
{
{1, 2, 3},
{4, 5, 6}
},
{
{7, 8, 9},
{10, 11, 12}
},
{
72
{13, 14, 15},
{16, 17, 18}
}
};

printf("First element: %d\n", threed[0][0][0]);

printf("Last element: %d\n", threed[2][1][2]);

for (int i = 0; i < 3; i++) {


printf("2D Array %d:\n", i + 1);
for (int j = 0; j < 2; j++) {
printf(" Row %d: ", j + 1);
for (int k = 0; k < 3; k++) {
printf("%d ", threed[i][j][k]);
}
printf("\n");
}
printf("\n");
}

return 0;
}

OUTPUT
First element: 1
Last element: 18
Row 1: 1 2 3
Row 2: 4 5 6

2D Array 2:
Row 1: 7 8 9
Row 2: 10 11 12

73
2D Array 3:
Row 1: 13 14 15
Row 2: 16 17 18

Q2

CODE
#include <stdio.h>

int isSymmetric(int matrix[][10], int size) {


for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if (matrix[i][j] != matrix[j][i]) {
return 0;
}
}
}
return 1;
}

int main() {
int size;

printf("Enter the size of the square matrix: ");


scanf("%d", &size);

int matrix[10][10];

printf("Enter the elements of the matrix:\n");


for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
scanf("%d", &matrix[i][j]);
}
}

if (isSymmetric(matrix, size)) {
printf("The matrix is symmetric.\n");
} else {
printf("The matrix is not symmetric.\n");
}

74
return 0;
}

OUTPUT
Enter the elements of the matrix:
1
1
1
1
1
1
1
1
1
The matrix is symmetric.
Q3

CODE
#include <stdio.h>

int main() {

int matrix1[6][6] = {
{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}
};

int matrix2[6][6] = {
{36, 35, 34, 33, 32, 31},
75
{30, 29, 28, 27, 26, 25},
{24, 23, 22, 21, 20, 19},
{18, 17, 16, 15, 14, 13},
{12, 11, 10, 9, 8, 7},
{6, 5, 4, 3, 2, 1}
};

int result[6][6];

for (int i = 0; i < 6; i++) {


for (int j = 0; j < 6; j++) {
result[i][j] = matrix1[i][j] + matrix2[i][j];
}
}

printf("The resulting matrix is:\n");


for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}

return 0;
}

OUTPUT
The resulting matrix is:
37 37 37 37 37 37
37 37 37 37 37 37
37 37 37 37 37 37
37 37 37 37 37 37
37 37 37 37 37 37
37 37 37 37 37 37

Q4

76
CODE
#include <stdio.h>

int main() {

int matrix1[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

int matrix2[3][3] = {
{9, 8, 7},
{6, 5, 4},
{3, 2, 1}
};

int result[3][3];

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
result[i][j] = 0;
}
}

;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}

;
printf("The resulting matrix is:\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", result[i][j]);
}
printf("\n");
}

return 0;

77
}

OUTPUT
The resulting matrix is:
30 24 18
84 69 54
138 114 90

Q5

CODE
#include <stdio.h>

void shiftLeftByTwo(int arr[], int size) {


int temp1 = arr[0];
int temp2 = arr[1];

for (int i = 0; i < size - 2; i++) {


arr[i] = arr[i + 2];
}

arr[size - 2] = temp1;
arr[size - 1] = temp2;
}

void printMatrix(int matrix[4][5]) {


for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
}

78
int main() {

int matrix[4][5] = {
{15, 30, 28, 19, 61},
{22, 33, 44, 55, 66},
{77, 88, 99, 11, 21},
{31, 41, 51, 61, 71}
};

printf("Original matrix:\n");
printMatrix(matrix);

for (int i = 0; i < 4; i++) {


shiftLeftByTwo(matrix[i], 5);
}

printf("\nMatrix after shifting rows left by two positions:\n");


printMatrix(matrix);

return 0;
}

OUTPUT
Original matrix:
15 30 28 19 61
22 33 44 55 66
77 88 99 11 21
31 41 51 61 71

Matrix after shifting rows left by two positions:


28 19 61 15 30
44 55 66 22 33
99 11 21 77 88
51 61 71 31 41

79
80

You might also like