Text
Text
h>
int main() {
1 int num;
int times:
printf("How many numbers do you want to check? ");
scanf("%d", ×);
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);
}
}
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;
}