Saturday, November 21, 2015

Two Dimensional Array Demo in C

A simple program that I wrote in C language that demonstrate how to use Two Dimensional Array. The code is very simple and easy to understand perfect for beginners in C programming.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

#include <stdio.h>

 main()
{
    int arr[5][1], i=0, j=0, sum=0;

    printf("Two Dimensional Array Demo");
    printf("\n\n");
    for(i=0;i<5;i++)
    {
        for(j=0;j<1;j++)
        {
            printf("\nEnter the value for A[%d][%d] : ",i,j);
            scanf("%d",&arr[i][j]);
    }
    }

    for(i=0;i<5;i++)
    {
        for(j=0;j<1;j++)
        {
        sum=sum+arr[i][j];
        }
    }

    printf("\nThe sum of the elements of 2-D array is %d.", sum);
    printf("\n\n");
    printf("End of Program");
}



No comments:

Post a Comment