Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
#include<stdio.h>
#include<conio.h>
void main()
{
    int numArray[10];
    int i,sum=0;
    int *ptr;
    printf("\nEnter 10 elements:");
    for(i=0;i<10;i++)
    scanf("%d",&numArray[i]);
    ptr=numArray;
    for(i=0;i<10;i++)
    {
        sum=sum+ *ptr;
        ptr++;
    }
    printf("The sum of array elements:%d",sum);
    getch();
}

i have done this but i dont know how to do it with 2d array...please help..
Posted
Updated 23-Sep-14 3:31am
v2

1 solution

Much the same except you have two co-ordinates. Think of it in terms of rows and columns. So an array with three rows and five columns would be something like:
C++
#define NUM_ROWS 3
#define NUM_COLS 5
int array[NUM_ROWS][NUM_COLS];
int row, column;
for (row = 0; row < NUM_ROWS; row++)
{
    for (column = 0; column < NUM_COLS; column++)
    {
        array[row][column] = /* add value to this row and column of array */
    }
}
 
Share this answer
 
Comments
Abhinav Chaudhary 23-Sep-14 10:35am    
Okay Sir.Thanks..I'll try it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900