deCODE - Our Newsletter for Jan 2022 is available for Download. 🗞   🥳
  Signup/Sign In

Program to check if input Number is int or float

Below is a program to check whether the user input number is of integer or float datatype.

strlen() does not count the null character '\0'.



int main()
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
    char number[10];
    int flag = 0;
    int length, i = 0;

    printf("\n\nEnter a number: ");
    scanf("%s", number);

    length = strlen(number);

    // till string does not end
    while(number[i++] != '\0')    // same as while(length-->0)
        if(number[i] == '.')    // decimal point is present
            flag = 1;

    // if(0) is same as if(false)
        printf("\n\n\n\tEntered Number is a Floating point Number\n\n");
        printf("\n\n\n\tEntered Number is a integer Number\n\n");

    printf("\n\n\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;


Program to find if Input Number is Int or Float