Two and Multi-Dimensional Array in c



Two and Multi-Dimensional Array in c  


#include <stdio.h> 

#include <conio.h> 

void main() 

{ 

    int arr[2][3], i, j, total = 0; 

    printf("enter any 6 elemsnts in an array: \n"); 

    //row (we have 2 in an above mention array so i have use 2 in row loop) 

    for(i = 0; i<2; i++) 

    { 

        // column (we have 3 in an above array so i have use 3 in column loop ) 

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

        { 

            scanf("%d", &arr[i][j]); 

        } 

    } 

    printf("the elements are: \n"); 

     for(i = 0; i<2; i++) 

    { 

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

        { 

            printf("%d  ", arr[i][j]); 

            total = total + arr[i][j]; 

        } 

        printf("%d \n", total); 

        total = 0; //  

        printf("\n"); 

    } 

    getch(); 

} 

 

OUTPUT

enter any 6 elemsnts in an array: 

5 8 7 4 5 9 

the elements are: 

5  8  7  20 ---> sum


4  5  9  18---->sum


Follow our page for regular updates.

0 Comments

Newest