Write C Program to Print 2d Array and Calculate Sum of 2D Array In C -99webcode

 Write C Program to Print 2d Array and  Calculate Sum of 2D Array In C -99webcode

#include<stdio.h>
int main()
{
    int a[2][3],i,j,sum=0;  /*here we need two for loop so we ttake two variable i and j ,to
    calaculate sum of elemete take sum =0*/
    printf("enter elements for 2d array ");
    for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]); //accepting the the value for row and colomn
        }
    }
    printf("matrix is :\n");

   for(i=0;i<2;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%d\t",a[i][j]);//printing  the the value for row and colomn
            sum=sum+a[i][j];
        }
   

    printf("\n");
   
    }
printf("sum of array is:%d",sum);//printing the sum of all elementes of 2d array

}

output:
enter elements for 2d array
4 5 6 7 8 9 matrix is : 4 5 6 7 8 9
sum of array is:39





Post a Comment (0)
Previous Post Next Post