ตัวอักษรสุดท้ายได้ที่ตำแหน่งของตัวอักษรตัวแรกเท่านั้น คือจะไห้เรียงกันอะครับ 1 2 3 แบบนี้อะครับ
ตัวโปรแกรม
#include <stdio.h>
#include <conio.h>
int main (void) {
//(1) Local declarations
int row=4, col, num, letter;
int i, j;
//(2) Ask user to tell how many letters they want to print out.
printf ("How many letters they want to print out? ");
scanf ("%d", &num);
//(3) Assign the value of col
col = num*3;
//(4) Declare the variable B and initialization
int B[row][col];
for (i=0; i<row; i++)
for (j=0; j<col; j++)
B[j] = 0;
//(5) Ask the user for the first letter
printf ("Which letters they want to print out? [1='T' 2='O' 3='L'] ");
scanf ("%d", &letter);
//(6) Create each character
if (letter == 1) {
B[0][0] = 178;
B[0][1] = 178;
B[0][2] = 178;
B[1][1] = 178;
B[2][1] = 178;
B[3][1] = 178;
} else if (letter == 2) {
B[0][1] = 178;
B[0][2] = 178;
B[0][3] = 178;
B[1][1] = 178;
B[1][3] = 178;
B[2][1] = 178;
B[2][3] = 178;
B[3][1] = 178;
B[3][2] = 178;
B[3][3] = 178;
} else {
B[0][0] = 178;
B[1][0] = 178;
B[2][0] = 178;
B[3][0] = 178;
B[3][1] = 178;
B[3][2] = 178;
}
//(7) Print B
for (letter=0; letter<num; letter++)
for (i=0; i<row; i++) {
printf("| ");
for (j=0; j<col; j++)
printf ("%c", B[j]);
printf(" |\n");
}
getch ();
return 0;
}
รบกวนผู้รู้ช่วยแก้โปรแกรม ภาษา C หน่อยครับ งงมาก
ตัวโปรแกรม
#include <stdio.h>
#include <conio.h>
int main (void) {
//(1) Local declarations
int row=4, col, num, letter;
int i, j;
//(2) Ask user to tell how many letters they want to print out.
printf ("How many letters they want to print out? ");
scanf ("%d", &num);
//(3) Assign the value of col
col = num*3;
//(4) Declare the variable B and initialization
int B[row][col];
for (i=0; i<row; i++)
for (j=0; j<col; j++)
B[j] = 0;
//(5) Ask the user for the first letter
printf ("Which letters they want to print out? [1='T' 2='O' 3='L'] ");
scanf ("%d", &letter);
//(6) Create each character
if (letter == 1) {
B[0][0] = 178;
B[0][1] = 178;
B[0][2] = 178;
B[1][1] = 178;
B[2][1] = 178;
B[3][1] = 178;
} else if (letter == 2) {
B[0][1] = 178;
B[0][2] = 178;
B[0][3] = 178;
B[1][1] = 178;
B[1][3] = 178;
B[2][1] = 178;
B[2][3] = 178;
B[3][1] = 178;
B[3][2] = 178;
B[3][3] = 178;
} else {
B[0][0] = 178;
B[1][0] = 178;
B[2][0] = 178;
B[3][0] = 178;
B[3][1] = 178;
B[3][2] = 178;
}
//(7) Print B
for (letter=0; letter<num; letter++)
for (i=0; i<row; i++) {
printf("| ");
for (j=0; j<col; j++)
printf ("%c", B[j]);
printf(" |\n");
}
getch ();
return 0;
}