0% found this document useful (0 votes)
7 views9 pages

Lecture 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Lecture 2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Character and ASCII

Code in Clion or Mobile C


/* This program is to display the numerical value of ASCII character */
#include <stdio.h>

int main (void)


{
char a;
printf(“Enter a character: “);

// Reads character input from the user


scanf(“%c”, &a);

// %d displays the integer value of a character


// %c displays the actual character
printf(“ASCII value of %c = %d", a, a);

return 0;
}
Character and ASCII
Code in Dev C++ or Mobile C
ASCII Table from Reference
Deitel & Deitel Appendix B

q = 113
Character and ASCII
/* This program is to display the numerical value of ASCII character */ comments
#include <stdio.h>

int main (void)


{
char a;
printf(“Enter a character: “);

// Reads character input from the user


declare variable scanf(“%c”, &a); the ASCII character value
‘a’ as character is stored in variable a
data type // %d displays the integer value of a character
// %c displays the actual character
printf(“ASCII value of %c = %d", a, a);

return 0; exit program %d for integer


} %c for character
Quiz: Reverse the process,
Enter the decimal as user input
Display the ASCII character
ANS:

/* This program is to display the ASCII character given a numerical value*/


#include <stdio.h>

int main (void)


{
int a;
printf(“Enter a numerical value: “);

// Reads character input from the user


scanf(“%d”, &a);

// %d displays the integer value of a character


// %c displays the actual character
printf(“ASCII character of %d = %c", a, a);

return 0;
}
Quiz: Reverse the process,
Enter the decimal as user input
Display the ASCII character
Concept of Pseudo code

Kind of draft outline or sketch without worrying about the grammar, syntax etc.

Its like how you write daily journal. Content and your thoughts that count.

Pseudo-code is generic and programming language free


Example of
Pseudo code
/* This program is to display the numerical value of ASCII character
*/
#include <stdio.h>
Start program
int main (void)
Enter an ASCII character
{ Print the character and its
char a; equivalent numerical value
printf(“Enter a character: “); End program
// Reads character input from the user
scanf(“%c”, &a);
Start program
// %d displays the integer value of a character Declare a character variable a
// %c displays the actual character Enter an ASCII character
printf(“ASCII value of %c = %d", a, a); Scan the character into variable a
Print the character and its
return 0; equivalent numerical value
} End program
Self Study
Study some examples in the book Deitel and Deitel.

Generate pseudocode for those examples.

You might also like