You are on page 1of 3

#include<stdio.

h> output: 1 2 3
#include<conio.h> 4 5 6
void main(void) 7 8 9
{ 9
int a[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, c, r;
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
printf("%d ", a[r][c]);
}
printf("\n");

}
printf("%d ", a[2][2]);

_getch();

class activity

#include<conio.h>
#include<stdio.h>
main()
{
int a[3][3]={{5,6,9},{-4,5,-6},{7,-8,0}};
int b[9],r,c,d=0,temp,v,s,i,j;
for(r=0;r<=2;r++)
{
for(c=0;c<=2;c++)
{
b[d]=a[r][c];
d++;
}
}
for(r=0;r<=8;r++)
{
printf("%d",b[r]);
}
printf("\n");
for(v=0;v<=8;v++)
{
for(s=0;s<=7;s++)
{
if(b[s]>b[s+1])
{
temp=b[s];
b[s]=b[s+1];
b[s+1]=temp;
}
}
}
d=0;
for(r=0;r<=2;r++)
{
for(c=0;c<=2;c++)
{
a[r][c]=b[d];
d++;
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
getch();
}
same activity:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a[3][3] = { { -1, 0, 99 }, { 5, -7, 9 }, { -55, 2, 8 } }, c, s = 0, r, i,
j, temp = 0, d[9];
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
d[s] = a[r][c];
s++;

for (c = 0; c<= 8; c++)


{
for (r = 0; r<= 7; r++)
{
if (d[r] > d[r + 1])
{
temp = d[r];
d[r] = d[r+ 1];
d[r + 1] = temp;

}
}
}
s = 0;
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
a[r][c] = d[s];
s++;
}
}
for (r = 0; r <= 2; r++)
{
for (c = 0; c <= 2; c++)
{
printf("%d ", a[r][c]);
}
printf("\n");
}

_getch();

You might also like