Display matrix in two dimension array
I am newbie in c and trying to display an array in matrix form. I have
seen tutorials, but most of them deal with for loop to apply matrix
concept in a 2-D array. i m using while loop and examining it in my way.
It is although displaying in matrix form but it is not displaying the
accurate output. If i insert numbers 1,2..,9, it must show in the form as
below:
1 2 3
4 5 6
7 8 9
but it is displaying as :
1 2 4
4 5 7
7 8 9
I am unable to understand why it is happening.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j=0;
int arr[2][2];
clrscr();
while(i<=2)
{
j=0;
while(j<=2)
{
scanf("%d",&arr[i][j]);
j++;
}
i++;
}
i=0;
while(i<=2)
{
j=0;
while(j<=2)
{
printf("%d ",arr[i][j]);
//printf("%c",k);
j++;
//k++;
}
printf("\n");
i++;
}
printf("%d",arr[0][2]);
getch();
No comments:
Post a Comment