Advertisement
Dr4noel

Turning the matrix into a vector.

Nov 15th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. void main() {
  5.     int l, c, a[10][10], i, j, k[20];
  6.  
  7.     printf("Number of lines: ");
  8.     scanf_s("%d", &l);
  9.  
  10.     while (l > 10 || l < 1) {
  11.         printf("Insert the number of lines(from 1 to 10): ");
  12.         scanf_s("%d", &l);
  13.     }
  14.  
  15.     printf("Number of columns: ");
  16.     scanf_s("%d", &c);
  17.  
  18.     while (c > 10 | c < 1) {
  19.         printf("Insert the number of columns(from 1 to 10): ");
  20.         scanf_s("%d", &c);
  21.     }
  22.  
  23.     for (i = 0; i < l; i++) {
  24.         for (j = 0; j < c; j++) {
  25.             printf("V[%d][%d]= ", i, j);
  26.             scanf_s("%d", &a[i][j]);
  27.         }
  28.     }
  29.     printf("The matrix is : \n");
  30.     for(i = 0; i < l; i++) {
  31.         for (j = 0; j < c; j++) {
  32.             printf("%d ", a[i][j]);
  33.         }
  34.         printf("\n");
  35.     }
  36.     printf("For turninig the matrix into a vector, press any key.\n");
  37.     _getch();
  38.  
  39.     printf("V=[");
  40.     for (i = 0; i < l; i++) {
  41.         for (j = 0; j < c; j++) {  
  42.             k[j] = a[i][j];
  43.             printf("%d ", k[j]);
  44.         }
  45.     }
  46.     printf("]\n");
  47.     printf("\nPress any key to close the console.");
  48.     _getch();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement