Program
#include <stdio.h> int main() { printf("****************************************************"); printf("\n****************************************************"); printf("\n** WAP to find sum of elements of a 2D array **"); printf("\n** Created by Sheetal Garg **"); printf("\n** Assistant Professor **"); printf("\n** Phone No:9467863365 **"); printf("\n****************************************************"); printf("\n****************************************************\n"); int m, n, i, j, a[5][5],sum=0; printf("Enter no. of rows and columns in the array\n"); scanf("%d%d", &m, &n); printf("enter array elements\n"); for (i = 0; i < m; i++) for (j = 0; j < n; j++) { scanf("%d", &a[i][j]); sum=sum+a[i][j]; } printf("\nThe array elements are\n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) printf("%d\t", a[i][j]); printf("\n"); } printf("\nThe sum of elements is %d",sum); return 0; }
Output
**************************************************** **************************************************** ** WAP to find sum of elements of a 2D array ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** **************************************************** **************************************************** Enter no. of rows and columns in the array 3 3 enter array elements 2 3 4 3 4 2 1 4 1 The array elements are 2 3 4 3 4 2 1 4 1 The sum of elements is 24