Advertisement
Guest User

Azmy.c

a guest
May 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define ROWS 10
  4. #define COLS 10
  5.  
  6. void init(int Matrix2D[][COLS], int N, int M){
  7.     int i, j;
  8.     for (i = 0; i < N; i++)
  9.         for (j = 0; j < M; j++)
  10.             Matrix2D[i][j] = 0;
  11. }
  12.  
  13. void setRow(int Matrix2D[][COLS], int M, int rowIndex, int value){
  14.     int i;
  15.     for (i = 0; i < M; i++)
  16.     {  
  17.         Matrix2D[rowIndex][i] = value;
  18.     }
  19. }
  20.  
  21. void print2DArray(int Matrix2D[ROWS][COLS], int N, int M){
  22.     int i, j;
  23.     for (i = 0; i < N; i++)
  24.     {
  25.         for (j = 0; j < M; j++)
  26.         {
  27.             printf("\t %d",Matrix2D[i][j]);
  28.         }
  29.         printf("\n");
  30.     }
  31. }
  32.  
  33.  
  34.  
  35. int main(){
  36.  
  37.     //get the dimensions of the 2D array
  38.     printf("enter the 1st 2D Matrix dimension (must be less than %d): ",ROWS);
  39.     int N;
  40.     scanf("%d",&N);
  41.     printf("enter the 2nd 2D Matrix dimension (must be less than %d): ",COLS);
  42.     int M;
  43.     scanf("%d",&M);
  44.    
  45.     //creating the 2D array
  46.     int Matrix2D[N][M];
  47.    
  48.     // initialize or fill it with zeros
  49.     init(Matrix2D, N, M);
  50.    
  51.     //get the needed info
  52.     printf("which row do u want to set : ");
  53.     int rowIndex;
  54.     scanf("%d",&rowIndex);
  55.     printf("enter the value : ");
  56.     int value;
  57.     scanf("%d",&value);
  58.    
  59.     // set the whole row with that value
  60.     setRow(Matrix2D, M, rowIndex-1, value);
  61.    
  62.     //print the whole array
  63.     print2DArray(Matrix2D, N, M);
  64.    
  65.     return 0;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement