9.4.20

sum of elements of a matrix


SUM OF ELEMENTS OF A MATRIX
#include <stdio.h>
void main()
{

    int m[5][5],r,c,i,j,s=0;
    printf("How many rows and cols");
    scanf("%d%d",&r,&c);
    printf("enter elements");
    for(i=0;i<r;i++)
        for(j=0;j<c;j++)
    {
        scanf("%d",&m[i][j]);
        s=s+m[i][j];
    }
printf("sum of elements =%d",s);
    22
   
}
OUTPUT
How many rows and cols 2
4
Enter elements 1
2
3
4
5
6
7
8
Sum of elements 36

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...