Solved programming problem

Scan,Print and Multiply Matrix Using Function in C.

Source code

#include <stdio.h>

int inputmatrix() ///scan matrix

{

    int n,m;

    int array[100][100];

    printf("
Please Enter a 3X3 matrix:
");

    for(n=0; n<3; n++)

    {

        for(m=0; m<3; m++)

        {

            scanf("%d",&array[n][m]);

        }

    }

    return 0;

}

int  showmatrix() ///print matrix

{

    int n,m,array[100][100];

    printf("
Original Matrix:
");

    for(n=0; n<3; n++)

    {

        for(m=0; m<3; m++)

        {

            printf("%d ",array[n][m]);

        }

        printf("
");

    }

    return 0;

}

int scalarmatrix()  ///change matrix value

{

    int i,n,m,array[100][100],ans[100][100];

    printf("Please Enter The number which you want to multiply with the matrix: ");

    scanf("%d",&i);

    printf("
Multiplied by %d:
",i);

    for(n=0; n<3; n++)

    {

        for(m=1; m<=3; m++)

        {

            ans[n][m]=array[n][m]*i;

            printf("%d ",ans[n][m]);

        }

        printf("
");

    }

    return 0;

}

int main()

{

    inputmatrix();///for scan this function is called

    showmatrix();///for print this function is called

    scalarmatrix();///for change the matrix value this function is called

    return 0;

}

Output

Please Enter a 3X3 matrix:
1 2 3
4 5 6
7 8 9

Original Matrix:
1 2 3
4 5 6
7 8 9
Please Enter The number which you want to multiply with the matrix: 2

Multiplied by 2:
2 4 6
8 10 12
14 16 18

Join the discussion

Add your comment