Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ROWS 10
- #define COLS 10
- void init(int Matrix2D[][COLS], int N, int M){
- int i, j;
- for (i = 0; i < N; i++)
- for (j = 0; j < M; j++)
- Matrix2D[i][j] = 0;
- }
- void setRow(int Matrix2D[][COLS], int M, int rowIndex, int value){
- int i;
- for (i = 0; i < M; i++)
- {
- Matrix2D[rowIndex][i] = value;
- }
- }
- void print2DArray(int Matrix2D[ROWS][COLS], int N, int M){
- int i, j;
- for (i = 0; i < N; i++)
- {
- for (j = 0; j < M; j++)
- {
- printf("\t %d",Matrix2D[i][j]);
- }
- printf("\n");
- }
- }
- int main(){
- //get the dimensions of the 2D array
- printf("enter the 1st 2D Matrix dimension (must be less than %d): ",ROWS);
- int N;
- scanf("%d",&N);
- printf("enter the 2nd 2D Matrix dimension (must be less than %d): ",COLS);
- int M;
- scanf("%d",&M);
- //creating the 2D array
- int Matrix2D[N][M];
- // initialize or fill it with zeros
- init(Matrix2D, N, M);
- //get the needed info
- printf("which row do u want to set : ");
- int rowIndex;
- scanf("%d",&rowIndex);
- printf("enter the value : ");
- int value;
- scanf("%d",&value);
- // set the whole row with that value
- setRow(Matrix2D, M, rowIndex-1, value);
- //print the whole array
- print2DArray(Matrix2D, N, M);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement