II-152 Programming Concepts
Two Dimensional Array
11. Program to print array elements in reverse order.
void main()
{
int i,j;
int a[3][3]={{9,8,7},{6,5,4},{3,2,1}};
clrscr();
printf("Elements of an array in reverse order.
");
for(i=2;i>=0;i--)
{
for(j=2;j>=0;j--)
printf("%5d",a[i][j]);
printf("
");
}
getche();
}
OUTPUT:
Elements of an array in reverse order
1 2 3
4 5 6
7 8 9
12. Display odd numbers using two for loops.
#include <stdio.h>
#include <conio.h>
void main()
{
int j,k,x[4][2]={1,2,3,4,5,6,7,8};
clrscr();
for(j=0;j<4;j++)
for(k=0;k<1;k++)
printf(" %d",x[j][k]);
}
OUTPUT:
1 3 5 7
M07_ITL-ESL4791_02_SE_C07.indd 152 12/22/2012 5:03:01 PM