C Programming

Solved Example

Practice Questions

Exercise Question

Identify a character is alphabet, digit and more


Input a character and check it is an alphabet,digit,white space(space,tab,newline) or special symbol. If a character is alphabet then also check it is in uppercase or lowercase and vowel or consonant.

Program / Solution:

int main() {
	char ch;
	printf("Enter a character: ");
	if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <='z')) {
		printf("%c is an alphabet",ch);
		if(ch >= 'A' && ch <= 'Z') {
			printf(" and in uppercase");
		}else {
			printf(" and in lowercase");
		ch = tolower(ch);
		if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
			printf(" and a vowel");
		}else {
			printf(" and a consonent");
	}else if(ch >= '0' && ch <= '9') {
		printf("%c is a digit",ch);
	}else if(ch == ' ' || ch == '\t' || ch == '\r') {
		printf("Character belongs to a white space (space,tab,newline)");
	}else {
		printf("%c is a special symbol",ch);
	return 0;

Sample Output:

Enter a character: Y
Y is an alphabet and in uppercase and a consonent

Enter a character: 6
6 is a digit

Enter a character: @
@ is a special symbol

More Progarms of Decision Making in C

Calculate profit or loss

Check a number is even or odd

Check a number is positive or negative

Check a year is leap year or not

Find the first day of year

Find the youngest person

Absolute value of a number

Find area of rectangle is greater than perimeter

Check the points are co-linear or not

Check a point is inside,outside or on the circle

Check the axis of a point

Check the insurance eligibility and calculate premium

Calculate the library penalty charges

Calculate grade of a student