Hướng dẫn đọc số tiếng anh

Yêu cầu:
Viết chương trình hướng dẫn đọc số tiếng anh
– Nhập vào 1 số có 3 chữ số
– Hiển thị cách đọc ra màn hình
Ví dụ: 2014 -> two zero one four

Giải thuật:
– Dùng switch case hoặc if/else

Code

/************************************************************
* Author: VNCODING
* History
* 2016/12/19        first create    VNCODING
*************************************************************/

#include <stdio.h>
#include <conio.h>

const char *number_table[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};

int main()
{
    int num;
    do
    {
        printf("\nnum = ");
        scanf("%d", &num);
    }while(num < 100 || num > 999);

    printf("%s %s %s", number_table[num/100], number_table[num/10%10], number_table[num%10]);

    getch();
    return 0;
}

Kết quả:

Hướng dẫn đọc số tiếng anh
Hướng dẫn đọc số tiếng anh

2 Comments on Hướng dẫn đọc số tiếng anh

  1. printf(“%s %s %s”, number_table[num/100], number_table[num/10%10], number_table[num%10]);
    ai có thể giải thích đoạn code này được không ạ. Cảm ơn

Leave a Reply to khoa Cancel reply