Advertisement
heroys6

Lab 4

Nov 20th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 3
  4. #define M 4
  5.  
  6. int Y[N][M];
  7.  
  8. int i, j;
  9.  
  10. int assign_mass();
  11. int output();
  12.  
  13. int main()
  14. {
  15.     //int Y[N][M];
  16.  
  17.     printf("\t\t\t_. ..Matrix..builder..v1.0.. ._\n\n");
  18.  
  19.     assign_mass();
  20.     output();
  21.  
  22.     return 0;
  23. }
  24.  
  25. int assign_mass()
  26. {
  27.     int method;
  28.  
  29.     printf("Choose method:\n[1] Automatic assignation\n[2] Enter yourself\nYour choice: ");
  30.     scanf("%d", &method);
  31.  
  32.     if (method==1)
  33.     {
  34.         for (i=0; i<N; i++)
  35.         {
  36.             for (j=0; j<M; j++)
  37.             {
  38.                 Y[i][j]=rand() %255;
  39.             }
  40.         }
  41.     }
  42.     else if (method==2)
  43.     {
  44.         for (i=0; i<N; i++)
  45.         {
  46.             for (j=0; j<M; j++)
  47.             {
  48.                 do
  49.                 {
  50.                     printf("Enter value to socket with address [%d][%d]: ", i, j);
  51.                     scanf("%d", &Y[i][j]);
  52.                     if (Y[i][j]<0 || Y[i][j]>255)
  53.                         printf("Bad input! Value must be: [0,255]! Try again!\n");
  54.                 }
  55.                 while(Y[i][j]<0 || Y[i][j]>255);
  56.             }
  57.         }
  58.     }
  59.  
  60. return 0;
  61. }
  62.  
  63. int output()
  64. {
  65.     printf("\n");
  66.     for (i=0; i<N; i++)
  67.         {
  68.             for (j=0; j<M; j++)
  69.             {
  70.                 printf("%d\t",Y[i][j]);
  71.             }
  72.             printf("\n");
  73.         }
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement