We can do arithmetic operation on character lets see some operation:
so OUTPUT is :-
Find OUT Numerical VALue of a integer save as character:
you can see clearly in above program is int x=char variable -'0'
then x=value of integer save as character variable.
subtract a integer from a character:
#include<stdio.h>
main()
{
char c='z'; //initialising
char ch;
printf("\n c = %c",c);
ch=c-1; //subtracting integer from charater
printf("\n c-1=%c",ch);
}
OUTPUT:- is nothing but character corressponding to ASCII volue=ASCII volue of 'z'-1Using as comparison :
Here we compare character to find out whether input character is capital or small letter character.#include<stdio.h> #include<string.h> main() { char str[50]; printf("\n enter string containing both capital & small character :\n::"); gets(str); int len,i; len=strlen(str); printf("\n printing all character in capital letter\n:"); for(i=0;i<len;i++) {
if(str[i]>='A' && str[i]<='Z')
// use comparison to check letter is capital or not { printf("%c",str[i]); } } }
so OUTPUT is :-
#include<stdio.h>
main()
{
char ch;
int n;
printf("\n input no between 0 to 9 which will be save as charcter :");
ch=getchar();
n=ch-'0';
printf("\n enter volue in ineger=%d",n);
}
OUTPUT:you can see clearly in above program is int x=char variable -'0'
then x=value of integer save as character variable.
TO convert string of integer into integer :
A function defined in C name "atoi()" It convert integer string into real integer : Lets see an Example
#include<stdio.h>
main()
{
char str[10];
printf("\n insert string of digit :");
gets(str);
int n;
n=atoi(str);// convert to integer
printf("interger save as string is : %d",n);
}
OUTPut is :
No comments:
Post a Comment
THANKS FOR UR GREAT COMMENT