Pages

  • Home
  • About & Contact
  • Archive
  • C Programming Examples

20 February 2012

c program to print ascii character with ascii value

ASCII (American Standard Code for Information Interchange).
In this page I have shown 2 programs.First program is to print the ascii values with thier corresponding characters and the second program  is to print ascii value for given character.
c program to print ascii character table

here is the first program to print ascii table

#include<stdio.h>
void main()
{
      int i;
      printf("Here is the ascii values with their corresponding characters\n");
      for(i=1;i<=255;i++)
     {
                 //if(i%7==0)            
                 //printf("\n");

              printf("%3d %c\t",i,i);
     }
}

Extra information: In the above output you can see that no character is printed while printing characters for values 7,8,9,10,13.This is because this characters are non-displayable-characters.
ascii value 7 represents TAB
              10 represents Carriage return
              13 represents Enter

Here is the program to print ascii value for given character input.


#include<stdio.h>
void main()
{
     char c;
     printf("\nEnter any character\n");
     scanf("%c",&c);
     printf("ascii value of %c is %d",c,c);
}

ascii value


Explanation: We can print the ascii value by changing the format specifier of character %c to %d for integer.


14 comments:

  1. how to print '\' through c program

    ReplyDelete
  2. #include
    #include
    void main()
    {
    printf("this is how you can print \\ \n"); // two back slash will print /
    printf("this is how we can print \" "); // similarly / before " can print "
    getch();
    }

    ReplyDelete
  3. #include
    void main();
    {
    printf("\nenter any charector\n");
    scanf('%c,&c);
    printf('ascii value of %c is is %d',c,c);
    }

    ReplyDelete
  4. Anonymous11 May, 2013

    Excellent article. I definitely appreciate this site.
    Keep writing!

    My site: half price sky tv discount code

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. here is code 'hoe to print alphabet from ascii value'
      #include
      int main()
      {
      char i = 90;
      while(i >= 65)
      {
      printf("%d ascii value is %c\n",i,i);
      i--;
      }

      return 0;
      }

      Delete
  6. Write an assembly language which will solve the following expression F=[{(A-B+C*B)/D}-A+D]+C*A please solve it. must be need

    ReplyDelete
  7. #include
    main()
    {
    int v,bit;
    v=0;
    while(v<=127)
    {

    printf(" %d %c\n",v,v); //for printing ascc
    v++;

    bit=7;
    while(bit>=0)
    {
    printf("%d",(v>>bit)&1);
    bit--;
    }

    }

    }

    ReplyDelete
    Replies
    1. this is used for ascii printing as well as equivalent binary and decimal no of ascii.....

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. *********
    **** ****
    *** ***
    ** **
    * *

    ReplyDelete