Advertisement
Salman_CUET_18

multiplication table

Mar 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int n, x, i, j;
  5.     int  value,count = 0, starting;
  6.     int matrix[500][500];
  7.  
  8.     scanf("%d%d", &n, &x);
  9.  
  10.     for(i = 0; i < n; i++)
  11.     {
  12.         /// i indicates row and j indicates column
  13.  
  14.         starting = i + 1;
  15.  
  16.         /* as i will start at zero, but we want to start at 1,
  17.          so we add additional 1 with the value of i*/
  18.  
  19.         /*first element of first row is, starting = 1(i = 0 + 1) and following
  20.         elements will increment according the first element of the column*/
  21.  
  22.         value = starting;
  23.  
  24.         if(value == x)
  25.         {
  26.                 count++;
  27.         }
  28.  
  29.         //this count is done in case first element of the row match with the value of x;
  30.  
  31.         for(j = 0; j < n; j++)
  32.         {
  33.             matrix[i][j] = value;
  34.             value = value + starting;
  35.  
  36.             /// value will increase by the value + starting, starting indicates the increment
  37.  
  38.             if(value == x)
  39.             {
  40.                 count++;
  41.             }
  42.  
  43.         }
  44.         value = 0;
  45.     }
  46.     printf("%d",  count);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement