Array Program7 Define two-dimensional (2-D) array.

#include<stdio.h>

#include<conio.h>


void main()

{

int i, j, limit1, limit2, no[97][97];

clrscr();


printf("How many numbers you want as limit1? ");

scanf("%d", &limit1);


printf("How many numbers you want as limit2? ");

scanf("%d", &limit2);


printf("\nEnter numbers one by one\n");

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

{

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

{

printf("Enter number for limit1:%d and limit2:%d: ", i+1, j+1);

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

}

}


printf("\n\nYour %d by %d array as below\n\n", limit1, limit2);

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

{

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

{

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

}

printf("\n");

}



getch();

}


/*


How many numbers you want as limit1? 2

How many numbers you want as limit2? 3


Enter numbers one by one

Enter number for limit1:1 and limit2:1: 22

Enter number for limit1:1 and limit2:2: 34

Enter number for limit1:1 and limit2:3: 67

Enter number for limit1:2 and limit2:1: 8

Enter number for limit1:2 and limit2:2: 66

Enter number for limit1:2 and limit2:3: 9



Your 2 by 3 array as below


22 34 67

8 66 9


*/

No comments:

Post a Comment