C Programming language

adplus-dvertising
C Program example: Input an alphabet and change it to upper case
Previous Home Next
Input an alphabet and change its case

In this example we will learn how we can convert cases of an alphabet. In this we have enter an alphabet. If it is character between (a-z or A-Z). Then case will converted and if not then "Have entered alphabet is not character.....:)" message will display on screen.

In this we are including two header files of C library #include<stdio.h> and #include<conio.h>.

In this example we are including five predefined method. These are main(),clrscr(),printf(""),scanf() and getch(). Here we are using scanf() method is used to take input from keyboard.

In this we are declaring ch as a character variable. Then print a message to enter a alphabet .When you insert a alphabet then check .Is it between 65 -90?These are ASCII values for A(65) -Z(90). If it is then to make lower case add 32 which gives equivalent lower case of alphabet. else if character is between 97(a)-122(z) then the alphabet is lower case. Then we have subtract 32 else alphabet is not upper or lower character. Then print message "Have entered alphabet is not character.....:)".

/* input an alphabets and change its case */

#include<stdio.h>
#include<conio.h>
void main()
{
	char ch;
	clrscr();
	printf("Enter an alphabet:\t");
	scanf("%c",&ch);
	if(ch>=65 && ch<=90)
	{
		ch=ch+32;
		printf("You have enter a Caps Latter");
		printf("/n The lower case is =%c",ch);
	}
	else if(ch>=97 && ch<=122)
	{
		ch=ch-32;
		printf("Change in to uppercase=%c",ch);
	}
	else
		printf("Have entered alphabet is not character.....:)");
	getch();
}
Output :

Enter an alphabet: a

Change in to uppercase= A

Previous Home Next