Pages

Saturday, 19 October 2013

Programs using characters in C language


/* write a program to demonstrate character*/
#include<stdio.h>
#include<conio.h>
void main()
{
char ch=’c’;
clrscr();
printf(“\nch=%c”,ch);
getch();
}

Result:

Output:

Ch=c
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the character:”);
scanf(“%c”,&ch);
printf(“\nch=%c”,ch);
getch();
}

Result:
Input:
Enter the character: p

Output:
Ch=p

Note: with using characters we can perform arithmetical operations.
program
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the character:”);
scanf(“%c”,&ch);
ch=ch+1;
printf(“\nch=%c”,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<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the upper case Alphabet:”);
scanf(“%c”,&ch);
ch=ch+32;
printf(“\nch=%c”,ch);
getch();
}

Result:
Input:
Enter the upper case Alphabet: A

Output:
Ch=a
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the lower case Alphabet:”);
scanf(“%c”,&ch);
ch=ch-32;
printf(“\nch=%c”,ch);
getch();
}

Result:
Input:
Enter the lower case 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<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the alphabet:”);
scanf(“%c”,&ch);
if(ch==’a’||ch==’e’||ch==’I’||ch==’o’||ch==’u’)

{
printf(“it is lower case vowel”);
}
else  if(ch==’A’||ch==’E’||ch==’I’||ch==’O’||ch==’U’)
{
printf(“it is upper case vowel”);
}
else
{
printf(“it is not a vowel”);

}
getch();
}

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“enter the alphabet:”);
scanf(“%c”,&ch);
switch(ch)
{
case ‘a’:
case ‘e’:
case ‘i’:
case ‘o’:
case ‘u’:
          printf(“it is lower case vowel”);
          break;
case ‘A’:
case ‘E’:
case ‘I’:
case ‘O’:
case ‘U’:
        printf(“it is upper case vowel”);
        break;
default:
         printf(“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