C program to ASCII code for digit and backspace.

Q48. Write a C program to

  • print ASCII code for a given digit.
  • print ASCII code for backspace.

(Hint: Store escape sequence for backspace in an integer variable).

Ans(i).

#include<stdio.h>  //for standard input and output

#include<conio.h>  //for clrscr()

 

//Main Function

void main()

{

int num;

clrscr();  //for clear screen

 

printf(“\n Enter a digit you want to print the ASCII value of: “);

scanf(“%d”,&num);

 

printf(“\n The ASCII value of given number is: %c”,(char)num);

getch();  //To hold the output screen

}

//End of main()

 

Output:

 

Enter a digit you want to print the ASCII value of: 97

The ASCII value of given number is: a

 

Ans(ii).

#include<stdio.h>  //for standard input and output

#include<conio.h>  //for clrscr()

 

//Main Function

void main()

{

char num;

clrscr();  //for clear screen

 

num=’\b’;

 

printf(“\n The ASCII value of backspace is: %d”,(int)num);

getch();  //To hold the output screen

}

//End of main()

 

Output:

 

The ASCII value of backspace is: 8

Leave a Reply

Your email address will not be published. Required fields are marked *

39 Views
%d bloggers like this: