Program to check if the given character is a vowel or consonant
#include <stdio.h>
int main()
{
char ch;
printf("Enter a character\n");
scanf("%c", &ch);
// Checking both lower and upper case, || is the OR operator
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U')
printf("%c is a vowel.\n", ch);
else
printf("%c isn't a vowel.\n", ch);
return 0;
}
C program to check whether the character is an alphabet or not
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c",&c);
if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
printf("%c is an alphabet.",c);
else
printf("%c is not an alphabet.",c);
return 0;
}
Note-In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself.
The ASCII value of lowercase alphabets are from 97 to 122. And, the ASCII value of uppercase alphabets are from 65 to 90.
You can write if condition like-if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
C Program to find the ASCII value of a character.
#include <stdio.h>
int main()
{
char c;
printf("Enter a character: ");
// Reads character input from the user
scanf("%c", &c);
// %d displays the integer value of a character
// %c displays the actual character
printf("ASCII value of %c = %d", c, c);
return 0;
}
Note: In this program, user is asked to enter a character which is stored in variable c. The ASCII value of that character is stored in variable c rather than that variable itself.
When %d format string is used, 71 (ASCII value of 'G') is displayed.
When %c format string is used, 'G' itself is displayed.
C program to check whether a given character is upper case, lower case, number or special character
#include
int main()
{
//Fill the code
char ch;
scanf(“%c”,&ch);
if(ch >= 65 && ch <= 90)
printf(“Upper”);
else if(ch >= 97 && ch <= 122)
printf(“Lower”);
else if(ch >= 48 && ch <= 57)
printf(“Number”);
else
printf(“Symbol”);
return 0;
}
Odd or even program in C using modulus operator
#include <stdio.h>
int main()
{
int n;
printf("Enter an integer\n");
scanf("%d", &n);
if (n%2 == 0)
printf("Even\n");
else
printf("Odd\n");
return 0;
}