Write a C program to convert alphabet to number.
int main() {
int ch, option = 1;
while (option) {
printf("Enter your input character:");
ch = getchar();
if ((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z')) {
printf("Equivalent Number: %d\n", toascii(ch));
} else {
printf("Not a valid character!!\n");
}
getchar();
printf("Do you want to continue(1/0):");
scanf("%d", &option);
getchar();
}
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input character:A
Equivalent Number: 65
Do you want to continue(1/0):1
Enter your input character:Z
Equivalent Number: 90
Do you want to continue(1/0):0
Enter your input character:A
Equivalent Number: 65
Do you want to continue(1/0):1
Enter your input character:Z
Equivalent Number: 90
Do you want to continue(1/0):0
No comments:
Post a Comment