Advertisement
informaticage

Segment display C - Excercise

Jun 22nd, 2021 (edited)
1,235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void segment(int num);
  4. int main(void) {
  5.  
  6.   int to_print;
  7.    do {
  8.     printf("Num (-1 to exit): ");
  9.     scanf("%d", &to_print);
  10.     segment(to_print);
  11.     printf("\n");
  12.   } while(to_print != -1);
  13.  
  14.   return 0;
  15. }
  16.  
  17. void segment(int num) {
  18.   int array[10][7] = {
  19.       {1, 1, 1, 0, 1, 1, 1}, {0, 0, 1, 0, 0, 1, 0}, {1, 0, 1, 1, 1, 0, 1},
  20.       {1, 0, 1, 1, 0, 1, 1}, {0, 1, 1, 1, 0, 1, 0}, {1, 1, 0, 1, 0, 1, 1},
  21.       {1, 1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 0, 1, 0}, {1, 1, 1, 1, 1, 1, 1},
  22.       {1, 1, 1, 1, 0, 1, 1},
  23.   };
  24.  
  25.   // Prima riga
  26.   if (array[num][0]) {
  27.     printf(" _ ");
  28.   }
  29.   printf("\n");
  30.  
  31.   // Seconda riga
  32.   printf("%c", array[num][1] ? '|' : ' ');
  33.   printf("%c", array[num][3] ? '_' : ' ');
  34.  
  35.   if (array[num][2]) printf("|");
  36.  
  37.   printf("\n");
  38.  
  39.   // Terza riga
  40.   printf("%c", array[num][4] ? '|' : ' ');
  41.   printf("%c", array[num][6] ? '_' : ' ');
  42.  
  43.   if (array[num][5]) printf("|");
  44.  
  45.   printf("\n");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement