Practice Program
Solution:
void main()
{
int i,j;
int a[3][3],c[3][3];
for(i=0;i<3;i++)
{
, for(j=0;j<3;j++)
{
printf("\nEnter the element: ");
scanf("%d",&a[i][j]);
}
}
printf("\nArray element are: ");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j] = a[j][i];
}
}
printf("Transpose is : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
void main() { int i,j; int a[3][3],c[3][3]; for(i=0;i<3;i++) { , for(j=0;j<3;j++) { printf("\nEnter the element: "); scanf("%d",&a[i][j]); } } printf("\nArray element are: "); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } printf("\n"); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j] = a[j][i]; } } printf("Transpose is : \n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",c[i][j]); } printf("\n"); } }
Output1
Enter the Element:1
Enter the Element:2
Enter the Element: 3
Enter the Element: 4
Enter the Element:5
Enter the Element: 6
Enter the Element:7
Enter the Element:8
Enter the Element:9
Array element are: 1 2 3
4 5 6
7 8 9
Transpose is :
1 4 7
2 5 8
3 6 9
Output2
Enter the Element: 1
Enter the Element: 2
Enter the Element: 3
Enter the Element: 4
Enter the Element: 5
Enter the Element: 6
Enter the Element: 7
Enter the Element: 8
Enter the Element: 9
Array element are: 10 20 30
40 50 60
70 80 90
Transpose is :
10 40 70
20 50 80
30 60 90
defining a function 'transpose' which will print transpose of an array.
void transpose(int a[3][3])
{ int c[3][3];
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j] = a[j][i];
}
}
printf("Transpose is : \n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
void transpose(int a[3][3]) { int c[3][3]; int i,j; for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j] = a[j][i]; } } printf("Transpose is : \n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",c[i][j]); } printf("\n"); } }
Using above define function 'transpose()':
void main()
{
int i,j;
int a[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\nEnter the element: ");
scanf("%d",&a[i][j]);
}
}
printf("\n");
printf("Array element are:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
}
transpose(a);
}
void main() { int i,j; int a[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\nEnter the element: "); scanf("%d",&a[i][j]); } } printf("\n"); printf("Array element are:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } } transpose(a); }
Output1
Enter the Element:1
Enter the Element:2
Enter the Element: 3
Enter the Element: 4
Enter the Element:5
Enter the Element: 6
Enter the Element:7
Enter the Element:8
Enter the Element:9
Array element are: 10 20 30
40 50 60
70 80 90
Transpose is :
10 40 70
20 50 80
30 60 90
Enter the Element:2
Enter the Element: 3
Enter the Element: 4
Enter the Element:5
Enter the Element: 6
Enter the Element:7
Enter the Element:8
Enter the Element:9
Array element are: 10 20 30
40 50 60
70 80 90
Transpose is :
10 40 70
20 50 80
30 60 90
Using above define function 'transpose()':
void main()
{
int i,j;
int a[3][3];
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\nEnter the element: ");
scanf("%d",&a[i][j]);
}
}
printf("\n");
printf("Array element are:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
}
transpose(a);
}
void main() { int i,j; int a[3][3]; for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("\nEnter the element: "); scanf("%d",&a[i][j]); } } printf("\n"); printf("Array element are:"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } } transpose(a); }
Output2
Enter the Element:1
Enter the Element:2
Enter the Element: 3
Enter the Element: 4
Enter the Element:5
Enter the Element: 6
Enter the Element:7
Enter the Element:8
Enter the Element:9
Array element are: 1 2 3
4 5 6
7 8 9
Transpose is :
1 4 7
2 5 8
3 6 9
0 Comments
Post a Comment