0% found this document useful (0 votes)
3 views

Text

Uploaded by

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

Text

Uploaded by

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

Po1.#Using for loop #include <stdio.

h>
int main() {
1 int num;
int times:
printf("How many numbers do you want to check? ");
scanf("%d", &times);
for (int i = 0; i < times; i++) {
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even.\n", num);
} else i
printf("%d is odd.\n", num);
}
}

Using a while loop:


#include <stdio.h>
int main() {
int num;
int choice = 1;
while (choice) {
printf("Enter an integer: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("gd is even. \n", num);
} else {
printf("%d is odd. \n", num);
}
printf("Do you want to check another
number? (1 for Yes / 0 for No): ");
scanf("%d", &choice);
}
printf("Program ended. \n");
return 0;
}

Using a switch statement

int main () {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
switch (num % 2) {
case 0:
printf("d is even. \n", num);
break;
case 1:
printf("%d is odd.\n", num);
break;
}
printf("Program ended. \n");
return 0;
}

Pro 2 matrix

#include <stdio.h>
void multiplyMatrices(int a [5][5], int b[5[5],
int c[5][5], int r1, int c1, int r2, int c2) {
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
c[i][j] = 0;
for (int k = 0; k < c1; j++) {
c[i][j]+ = a[i][k]*b[k][j];
}
}
}
}
int main {
int a [5](5], b[5][5], c(5]|5];
int r1, c1, r2, c2;
printf("Enter the number of rows and
columns for Matrix-1: ");
scanf("%d %d", &r1, &c1);
// Input elements of the first matrix
printf("Enter the elements of Matrix-1:\n");
for (int i = 0; i < r1; i++) 1
for (int j = 0; j < c1; j++) 1
scanf("%d", &a(i]ül);
}
}
printf("Enter the number of rows and
columns for Matrix-2: ");
scanf("%d %d", &r2, &c2);
printf ("Enter the elements of Matrix-2:\n");
for (int i = 0; i < r2; i++) {
for (int j = 0; j < c2; j++) {
scanf("%d", &b[i][j]);
}
}
if (c1!= r2) {
printf("Operation can't be performed:
Columns of Matrix-1 must equal rows of Matrix-2.\n");
return 1;
}
multiplyMatrices(a, b, c, r1, c1, r2, c2);
printf("The product of the two matrices is :\n");
for (int i = 0; i < r1; i++) {
for (int j = 0; j < c2; j++) {
Printf(“%d\t”,c[i][j]);
}
Print(“\n”);
}
Return 0;
}

You might also like