Don't know why you want to store both the matrix format and the array format, but anyway here is a code that should do the trick with also the data output to show the result:
#include <stdio.h>
#include <stdlib.h>
#define R 20 //max rows
#define C 20 //max columns
int main() {
int m[R][C]; //matrix
int a[R*C]; //array
int r, c; //user matrix size
int i, j; //iterators
printf("insert row size: ");
scanf("%d", &r);
printf("insert column size: ");
scanf("%d", &c);
if(r > R || c > C) {
printf("Invalid sizes");
return -1;
}
for(i = 0; i < r; i++) {
for(j = 0; j < c; j++) {
printf("insert value for row %d column %d: ", i + 1, j + 1);
scanf("%d", &m[i][j]);
a[(c * i) + j] = m[i][j];
}
}
for(i = 0; i < r; i++) {
for(j = 0; j < c; j++) {
printf("%d ", m[i][j]);
}
printf("\n");
}
for(i = 0; i < r * c; i++) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
Note that I also added some checks for the user data, avoiding to generate a matrix bigger that the maximum size. Also you don't need separate loops but it can be done all together.
forloop out of the existing loops and into a seperatei/jloop. If that still doesn't work for you then please describe the problem in more detail than "didn't work". Give the exact input, expected result and actual result.}markers on a single line is anathema in C (except, presumably, to your professor(s)). You've indented the code by miles, but don't use spaces within lines; that also makes the code harder to read. The indentation isn't consistent; that too makes it harder to read. You have two 'loops' likefor(i=0;i<M;i++{where you've missed the)before the{. You declarecearly, but don't declareiorjat all. It is better if you post code that can be compiled! (The inner loop does not do what you want either.)scanf("%d %d",&M,&N);The variablesMandNare not declared anywhere in the posted code. Therefore, the posted code will not compile!}as a separate statement.