Skip to content
28 Juni 2009 / Jeffrey Hermanto Halimsetiawan

706 – LCD Display dengan Bahasa C


Program yang menampilkan angka dalam bentuk LCD Display [7-Segment] seperti di dalam kalkulator.

INPUT

The input file contains several lines, one for each number to be displayed. Each line contains two integers s, n (1 <= s <= 10, 0 <= n <= 99999999) where n is the number to be displayed and s is the size in which it shall be displayed.

The input file will be terminated by a line containing two zeros. This line should not be processed.

OUTPUT

Output the numbers given in the input file in an LC-display-style using s “-” signs for the horizontal segments and s “|” signs for the vertical ones. Each digit occupies exactly s+2 columns and 2s+3 rows. (Be sure to fill all the white space occupied by the digits with blanks, also for the last digit.) There has to be exactly one column of blanks between two digits.

Output a blank line after each number. (You will find a sample of each digit in the sample output.)

SAMPLE INPUT


2 12345
3 67890
0 0

SAMPLE OUTPUT


      --   --        --
   |    |    | |  | |
   |    |    | |  | |
      --   --   --   --
   | |       |    |    |
   | |       |    |    |
      --   --        -- 

 ---   ---   ---   ---   ---
|         | |   | |   | |   |
|         | |   | |   | |   |
|         | |   | |   | |   |
 ---         ---   ---
|   |     | |   |     | |   |
|   |     | |   |     | |   |
|   |     | |   |     | |   |
 ---         ---   ---   ---

SOLUTION

Untuk menyelesaikan masalah ini, kita dapat mengasosiasikan bentuk-bentuk angka tersebut ke dalam bentuk 7-segment


  0
  -
1| |2
3 _
4| |5
  _
  6

Contoh : angka 7 maka akan dimodelkan dalam bentuk 1,0,1,0,0,1,0


 --
   |
   |

   |
   |

Nah, nantinya kita akan memiliki tabel yang berisi bentuk 7-segment dari angka 0 sampai 9 dalam bentuk array dua dimensi. Kemudian, kita tinggal melakukan looping agar mendapatkan hasil yang sesuai dengan sample input. Sebagai ilustrasi, langkah-langkah prosesnya adalah sebagai berikut :

Input : 2 23
2 — > 11 , 10, 11, 11, 11, 10, 11
3 — > 11 , 10, 11, 11, 10, 11, 11
11 mewakili 1 dan 10 mewakili 0


- Langkah 1
 --   --

- Langkah 2
 --   --
   |    |

- Langkah 3
 --   --
   |    |
   |    |

- Langkah 4
 --   --
   |    |
   |    |
 --   --

- Langkah 5
 --   --
   |    |
   |    |
 --   --
|       |

- Langkah 6
 --   --
   |    |
   |    |
 --   --
|       |
|       |

- Langkah 7
 --   --
   |    |
   |    |
 --   --
|       |
|       |
 --   --

SOURCE CODE


#include < stdio.h>

char tempNumber[10][7] = { {11 , 11, 11, 10, 11, 11, 11}, // 0
                           {10 , 10, 11, 10, 10, 11, 10}, // 1
                           {11 , 10, 11, 11, 11, 10, 11}, // 2
                           {11 , 10, 11, 11, 10, 11, 11}, // 3
                           {10 , 11, 11, 11, 10, 11, 10}, // 4
                           {11 , 11, 10, 11, 10, 11, 11}, // 5
                           {11 , 11, 10, 11, 11, 11, 11}, // 6
                           {11 , 10, 11, 10, 10, 11, 10}, // 7
                           {11 , 11, 11, 11, 11, 11, 11}, // 8
                           {11 , 11, 11, 11, 10, 11, 11}, // 9
                         };

int main()
{
    int i,j,k,l,
        n,m;
    char input[10];
    while (scanf("%d %s",&n,input) == 2 ){
          if (n == 0 && input[0] == '0')
             break;
          for (j=0;j<7;j++){
              if ( j == 2 || j == 5) j++;
              if (j == 1 || j == 4 )
                    m = n;
              else
                    m = 1;
              for (k=0;k

Untuk lebih lengkapnya, silahkan download PDF Version nya di bawah :p

Mudah kan untuk menyelesaikan masalah di atasđŸ˜€

Download PDF Version : 706 – LCD Display dalam Bahasa C

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: