0

## 用函式來傳達你的心意> 0 <

``````int main()
{
int seats[10] = {99, 0, 10, 31, 0, 42, 70, 67, 0, 0};
int i, j, seat, number;
printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}

printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
while(number != 0){
if(seats [seat - 1] == 0){
seats[seat - 1] = number;
printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
}
else{
printf("Sorry, seat is taken.\n");
scanf("%d %d", &seat, &number);
}
}

printf("*seating*\n");
bubble_sort(seats, 10);
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
printf("\n");
printf("***************\n");

return 0;
}
``````

``````printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
``````

``````while(number != 0){
if(seats [seat - 1] == 0){
seats[seat - 1] = number;
printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
}
else{
printf("Sorry, seat is taken.\n");
scanf("%d %d", &seat, &number);
}
}

``````

``````    if(seats [seat - 1] == 0){
seats[seat - 1] = number;
printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
}
else{
printf("Sorry, seat is taken.\n");
scanf("%d %d", &seat, &number);
}
``````

``````        seats[seat - 1] = number;
printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
``````

``````        seats[seat - 1] = number;

printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}

printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
``````

``````    printf("*seating*\n");
for(int i = 0; i < 10; ++i){
printf("%d ", seats[i]);
}
``````
``````    printf("\n");
printf("***************\n");
printf("Please input the seat (1~10) and 2-digit number(0 to end game)\n");
scanf("%d %d", &seat, &number);
``````

``````void showSeats(int seats[], int length)
{
printf("*seating*\n");
for(int i = 0; i < length; ++i){
printf("%d ", seats[i]);
}
}

void getUserInput(int& seat, int& number){
printf("\n");
printf("***************\n");
printf("Please input the seat (0~9) and number(-1 to end game)\n");
scanf("%d %d", &seat, &number);
}

int main()
{
int seats[10] = {99, 0, 10, 31, 0, 42, 70, 67, 0, 0};
int i, j, seat, number;
showSeats(seats, 10);

getUserInput(seat, number);

while(number != 0){
if(seats [seat - 1] == 0){
seats[seat - 1] = number;

showSeats(seats, 10);

getUserInput(seat, number);
}
else{
printf("Sorry, seat is taken.\n");
scanf("%d %d", &seat, &number);
}
}

bubble_sort(seats, 10);

showSeats(seats, 10);

printf("\n");
printf("***************\n");

return 0;
}
``````