* In this above Format of 3 Ways to fill 3 X 3 integer array with user input.
With out using loops
#include<stdio.h> #include<conio.h> void main() { int a[3][3]={{4,5,6},{8,9,2},{2,7,9},}; clrscr(); printf("3 * 3 Matrix values are:\n"); printf("%d ",a[0][0]); printf("%d ",a[0][1]); printf("%d ",a[0][2]); printf("\n%d ",a[1][0]); printf("%d ",a[1][1]); printf("%d ",a[1][2]); printf("\n%d ",a[2][0]); printf("%d ",a[2][1]); printf("%d ",a[2][2]); getch(); } |
With using for loop
#include<stdio.h> #include<conio.h> void main() { int i,a[3][3]={{4,5,6},{8,9,2},{2,7,9},}; clrscr(); printf("3 * 3 Matrix values:\n"); for(i=0;i<3;i++) { printf("%d ",a[0][i]); } printf("\n"); for(i=0;i<3;i++) { printf("%d ",a[1][i]); } printf("\n"); for(i=0;i<3;i++) { printf("%d ",a[2][i]); } getch(); } |
With using nested for loop
#include<stdio.h> #include<conio.h> void main() { int i,j,a[3][3]={{4,5,6},{8,9,2},{2,7,9},}; clrscr(); printf("3 * 3 matrix values:\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d ",a[i][j]); } printf("\n"); } getch(); } |
________________________________________
_______________________________________________________________________________
Post a Comment