This blog is under construction

Saturday, 6 July 2013

C program to convert alphabetic to numeric

Write a C program to convert alphabet to number.

  #include <stdio.h>
  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");
                printf("Do you want to continue(1/0):");
                scanf("%d", &option);
        return 0;

  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

No comments:

Post a Comment