Character Data Type In C Language | Find Given Number Is Positive Or Negative And Find Given Number Is Big Or Small Compare To Other Number.

Character data type in c language | Find given number is positive or negative | Find given number is big or small comapare to other number

1. Introducation to character(char) data type

2. Find given number is positive or negative using character data type

3. Find given number is big or small compare to other number using character data type

Introducation to character(char) data type :

It stores a single character and requires a single byte of memory in almost all compilers.

Example - 1 : Find given number is positive or negative using character data type :

#include <stdio.h>
int main()
{
    char ch1;
    printf("Enter Number To Find Number is Positive Or Negative : ");
    scanf("%c", &ch1);

    if (ch1 >= '0')
    {
        printf("Number is positive");
    }
    else
    {
        printf("Number is Negative");
    }
    return 0;
}

Output:

Enter Number To Find Number is Positive Or Negative : 10
Number is positive

Example - 2 : Find given number is big or small compare to other number using character data type :

#include <stdio.h>
int main()
{
    char ch1;
    char ch2;
    printf("Enter First Number: ");
    scanf("%c", &ch1);
    fflush(stdin);/*Use of fflush : fflush is to clear (or flush) the output buffer and move the buffered data to console (in case of stdout) or disk (in case of file output stream)*/
    printf("Enter Second Number : ");
    scanf("%c", &ch2);

    if (ch1 > ch2)
    {
        printf("%c is big compare to %c", ch1, ch2);
    }
    else if (ch1 < ch2)
    {
        printf("%c is small compare to %c", ch1, ch2);
    }
    else
    {
        printf("%c is equals to %c", ch1, ch2);
    }
    return 0;
}

Output:

Enter First Number: 5
Enter Second Number : 3
5 is big compare to 3

Post a Comment

0 Comments