Hàm isdigit() kiểm tra kí tự là kiểu số

int isdigit(int c);

Parameter:

c : tham số đầu vào kiểu int

Remark:

Hàm isdigit( ) kiểm tra tham số c. Nếu c là số thập phân(0 – 9), hàm sẽ trả về giá trị khác 0. Và nếu c không phải là số thập phân, hàm sẽ trả về giá trị 0.

Ví dụ: kiểm tra c1 = 50 và c2 = 54 có phải là số thập phân không?

#include "stdio.h"
#include "conio.h"
#include "ctype.h"

void main()
{
    int c1 = 50, c2 = 54;
    if(isdigit(c1))
        printf("\nc1 is decimal digit");
    else
        printf("\nc1 is NOT decimal digit");

    if(isdigit(c2))
        printf("\nc2 is decimal digit");
    else
        printf("\nc2 is NOT decimal digit");

    getch();
}

Kết quả:

Hàm isdigit( ) kiểm tra kí tự là kiểu số

 

Be the first to comment

Leave a Reply