Character:
/* write a program to demonstrate character*/
| |
#include<iostream.h>
#include<conio.h>
void main()
{
char ch=’c’;
clrscr( );
cout<<“\nch=“<<ch;
getch( );
}
Result:
Output:
Ch=c
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the character:”;
cin>>ch;
cout<<“\nch=“<<ch;
getch( );
}
Result:
Input:
Enter the character: p
Output:
Ch=p
|
Note: with using characters we can perform arithmetical operations.
program
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the character:”;
cin>>ch;
ch=ch+1;
cout<<“\nch=“<<ch;
getch( );
}
Result:
Input:
Enter the character: k
Output:
Ch=l
|
/* write a program to convert uppercase to lowercase alphabet*/
|
/* write a program to convert lowercase to uppercase alphabet*/
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the upper case alphabet:”;
cin>>ch;
ch=ch+32;
cout<<“\nch=“<<ch;
getch( );
}
Result:
Input:
Enter the uppercase alphabet: A
Output:
Ch=a
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the lower case alphabet:”;
cin>>ch;
ch=ch-32;
cout<<“\nch=“<<ch;
getch( );
}
Result:
Input:
Enter the lowercase alphabet: k
Output:
Ch=K
|
/* write a program to find given alphabet is vowel or not using else if */
|
/* write a program to find given alphabet is vowel or not using switch */
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the alphabet:”;
cin>>ch;
if(ch==’a’||ch==’e’||ch==’I’||ch==’o’||ch==’u’)
{
cout<<“it is lower case vowel”;
}
else if(ch==’A’||ch==’E’||ch==’I’||ch==’O’||ch==’U’)
{
cout<<“it is upper case vowel”;
}
else
{
cout<<“it is not a vowel”;
}
getch( );
}
|
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
clrscr( );
cout<<“enter the alphabet:”;
cin>>ch;
switch(ch)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
cout<<“it is lower case vowel”;
break;
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
cout<<“it is upper case vowel”;
break;
default:
cout<<“it is not a vowel”;
break;
}
getch( );
}
|
Result:
Input:
Enter the alphabet: A
Output:
it is vowel
|
Result:
Input:
Enter the alphabet: A
Output:
it is vowel
|
No comments:
Post a Comment