All
All
#include <stdio.h>
int main() {
int a[3][3]; // 2D array with max size 3*3
int rows, cols;
// Input elements
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
printf("Enter element at [%d][%d]: ", i, j);
scanf("%d", &a[i][j]);
}
}
// Display elements
printf("\nThe 2D array is:\n");
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
printf("%d\t", a[i][j]);
}
printf("\n");
}
return 0;
}
// Print first matrix
Sum of two matrices(display k liye ek or printf("\nFirst Matrix:\n");
loop & print) for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
#include <stdio.h> printf("%d\t", a[i][j]);
}
int main() { printf("\n");
int a[3][3], b[3][3], sum[3][3]; }
int rows, cols;
// Input second matrix
// Input matrix size printf("\nEnter elements of second
printf("Enter number of rows (max 10): "); matrix:\n");
scanf("%d", &rows); for(int i = 0; i < rows; i++) {
printf("Enter number of columns (max 10): "); for(int j = 0; j < cols; j++) {
scanf("%d", &cols); printf("b[%d][%d] = ", i, j);
scanf("%d", &b[i][j]);
// Input first matrix }
printf("\nEnter elements of first matrix:\n"); }
for(int i = 0; i < rows; i++) { // Print second matrix
for(int j = 0; j < cols; j++) { printf("\nSecond Matrix:\n");
printf("a[%d][%d] = ", i, j); for(int i = 0; i < rows; i++) {
scanf("%d", &a[i][j]); for(int j = 0; j < cols; j++) {
} printf("%d\t", b[i][j]);
} }
printf("\n");
}
// Calculate sum of the two matrices
for(int i = 0; i < rows; i++) {
for(int j = 0; j < cols; j++) {
sum[i][j] = a[i][j] + b[i][j];
}
}
return 0;
}
Multiply
#include <stdio.h> // Input elements of first matrix
printf("\nEnter elements of first
int main() { matrix:\n");
int a[10][10], b[10][10], product[10][10]; for(int i = 0; i < r1; i++) {
int r1, c1, r2, c2; for(int j = 0; j < c1; j++) {
printf("a[%d][%d] = ", i, j);
// Input sizes of matrices scanf("%d", &a[i][j]);
printf("Enter rows and columns of first matrix: "); }
scanf("%d %d", &r1, &c1); }
printf("Enter rows and columns of second matrix: "); // Input elements of second matrix
scanf("%d %d", &r2, &c2); printf("\nEnter elements of second
matrix:\n");
// Check multiplication condition for(int i = 0; i < r2; i++) {
if (c1 != r2) { for(int j = 0; j < c2; j++) {
printf("Matrix multiplication not possible. Columns printf("b[%d][%d] = ", i, j);
of first must equal rows of second.\n"); scanf("%d", &b[i][j]);
return 0; }
} }
// Initialize product matrix to 0
for(int i = 0; i < r1; i++) {
for(int j = 0; j < c2; j++) {
product[i][j] = 0;
}
}
return 0;
}
Transverse
#include <stdio.h>
int main() {
int a[10][10], transpose[10][10];
int rows, cols;
return 0;
}
C Program to Find Sum of All Elements of an Array
include <stdio.h>
int main() {
int arr[100], n, sum = 0;
return 0;
}
PRIME OR NOT
#include <stdio.h>
int main() {
int num, i, count = 0;
return 0;
}