StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #24 (U3): Matrix Addition and Subtraction
Download
  1. C Programming
  2. C Programming Practice
Program #23 (U3): Array Statistics via Functions : Program #25 (U3): Matrix Multiplication with Compatibility Check
C Programming Practice

Task: Read dimensions and two matrices of the same size. Compute A±B element-wise and print the result matrices (limit 50×50 to keep it simple).

 
#include <stdio.h>

 
int main(void) {

    int r, c;

    int A[50][50], B[50][50], C[50][50];

 
    printf("Enter rows and cols (<=50): ");

    if (scanf("%d %d", &r, &c) != 2 || r <= 0 || c <= 0 || r > 50 || c > 50) { printf("Invalid size.\n"); return 0; }

 
    printf("Enter matrix A (%d x %d):\n", r, c);

    for (int i = 0; i < r; ++i)

        for (int j = 0; j < c; ++j) scanf("%d", &A[i][j]);

 
    printf("Enter matrix B (%d x %d):\n", r, c);

    for (int i = 0; i < r; ++i)

        for (int j = 0; j < c; ++j) scanf("%d", &B[i][j]);

 
    printf("A + B =\n");

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

        for (int j = 0; j < c; ++j) { C[i][j] = A[i][j] + B[i][j]; printf("%d ", C[i][j]); }

        printf("\n");

    }

 
    printf("A - B =\n");

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

        for (int j = 0; j < c; ++j) { C[i][j] = A[i][j] - B[i][j]; printf("%d ", C[i][j]); }

        printf("\n");

    }

 
    return 0;

}

 

 

Program #23 (U3): Array Statistics via Functions Program #25 (U3): Matrix Multiplication with Compatibility Check
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website