7)Write a C program to store representation of 2-D array.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,j,m,n,ba;
clrscr();
printf(“\nEnter the No of Rows”);
scanf(“%d”,&m);
printf(“\nEnter the No. of Cols”);
scanf(“%d”,&n);
printf(“\nEnter the Base Address”);
scanf(“%d”,&ba);
printf(“\nEnter the Row Index”);
scanf(“%d”,&i);
printf(“\nEnter the Col Index”);
scanf(“%d”,&j);
if(i==0 && j==0)
printf(“\nAddress is \t %d”,ba);
else
{
if(i>=m || j>=n)
{
printf(“\nInvalid Index”);
}
else
{
a=ba+((i*n)+j)*sizeof(int);
printf(“\nAddress is %d\t”,a);
}
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s