-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab3_matrix_trans2.c
52 lines (51 loc) · 946 Bytes
/
Lab3_matrix_trans2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#define size 3
void initial(int a[][size],int row,int col)
{
printf("ENTER ELEMENTS OF ARRAY:\n");
for (int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
scanf("%d",&a[i][j]);
}
}
}
void swap(int *a,int *b)
{
int temp=*a;
*a=*b;
*b=temp;
}
void trans(int a[][size],int row,int col)
{
int i,j;
for (i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if (i+j<i+i)
swap(&a[j][i],&a[i][j]);
}
}
}
int main()
{
int a[size][size],row,col;
printf("ENTER NUMBER OF ROWS:");
scanf("%d",&row);
printf("ENTER NUMBER OF COLUMNS:");
scanf("%d",&col);
initial(a,row,col);
trans(a,row,col);
printf("MATRIX AFTER TRANSPOSE: \n");
for(int i=0;i<row;i++)
{
for(int j=0;j<col;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
return 0;
}