1
computer doesn't care if it is character or a number it always convert everything into number.
Whenever you program in C programming you can change int and char interchangeably almost all the time.
#include<stdio.h>
#include<ctype.h> ( this gives us bunch of built in characters, make sure you have included this one)
int main() {
int apple = 'b';
if( isalpha(apple)) (it's going to return true if b is a letter) {
printf("%c is a letter", apple);
}
return 0 ;
}
2
#include<stdio.h>
#include<ctype.h>
int main() {
int apple = '9';
if( isalpha(apple)) {
printf("%c is a letter", apple);
}
else {
if( isdigit(apple)) {
printf("%c is a number", apple);
} }
return 0 ;
}
3
#include<stdio.h>
#include<ctype.h>
int main() {
int apple = '$';
if( isalpha(apple)) {
printf("%c is a letter", apple);
}
else {
if( isdigit(apple)) {
printf("%c is a number", apple);
}else {
printf("%c is a OMG WTF is that!? ", apple);
}
}
return 0 ;
}
Comments
Post a Comment