Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define N 3
- #define M 4
- int Y[N][M];
- int i, j;
- int assign_mass();
- int output();
- int main()
- {
- //int Y[N][M];
- printf("\t\t\t_. ..Matrix..builder..v1.0.. ._\n\n");
- assign_mass();
- output();
- return 0;
- }
- int assign_mass()
- {
- int method;
- printf("Choose method:\n[1] Automatic assignation\n[2] Enter yourself\nYour choice: ");
- scanf("%d", &method);
- if (method==1)
- {
- for (i=0; i<N; i++)
- {
- for (j=0; j<M; j++)
- {
- Y[i][j]=rand() %255;
- }
- }
- }
- else if (method==2)
- {
- for (i=0; i<N; i++)
- {
- for (j=0; j<M; j++)
- {
- do
- {
- printf("Enter value to socket with address [%d][%d]: ", i, j);
- scanf("%d", &Y[i][j]);
- if (Y[i][j]<0 || Y[i][j]>255)
- printf("Bad input! Value must be: [0,255]! Try again!\n");
- }
- while(Y[i][j]<0 || Y[i][j]>255);
- }
- }
- }
- return 0;
- }
- int output()
- {
- printf("\n");
- for (i=0; i<N; i++)
- {
- for (j=0; j<M; j++)
- {
- printf("%d\t",Y[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement