-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion3.c
More file actions
37 lines (36 loc) · 776 Bytes
/
Question3.c
File metadata and controls
37 lines (36 loc) · 776 Bytes
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
#include <stdio.h>
int main()
{
int r, c;
printf("Enter the order of 2D matrix (row*col)\n");
scanf("%d %d", &r, &c);
int a[r][c];
printf("Enter the 2D array\n");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
scanf("%d", &a[i][j]);
}
int n = r * c;
int b[n];
int k = 0;
printf("Inital 2D Array:\n");
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
printf("%d ", a[i][j]);
printf("\n");
}
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
b[k] = a[i][j];
k++;
}
}
printf("\n Final 1D array:\n");
for (int i = 0; i < n; i++)
printf("%d ", b[i]);
return 0;
}