ascii code programming

Write a program in C, output ASCII code

Write a program in C, and then output ASCII code can be characters in the form of integer output that is output ASCII code, the specific programming ideas and methods are as follows:

How to program to find the ASCII code of any input character?

getchar() reads the input character

assigns the return value to a variable of type int, which is the requested ASCII code

#include <stdio.h>

int main()

{

int a = getchar();

printf(“%d\n”, a);//output the int value which is the ASCII code of the character read

return 0;

}

If you have already read in the character a which is of type char, then it is sufficient to directly convert the char to int.

char a=’a’;

int i;

i=a;//i is the ASCII code for a

Programming in C: After inputting three characters, output the three characters in the order of ASCII code of each character from smallest to largest.

The source code for outputting the three characters in order of ASCII code from smallest to largest is as follows:

#include&lt;

stdio.h&gt;

voidmain()

{

chara,s,c;

charmax,min;

printf(“Pleaseinputthreenumbers:”);

scanf(“%c,%c,%c”,&amp;a,&amp;b,&amp;c);

max=a;

< p>if(max&lt;b)max=b;

if(max&lt;c)max=c;

printf(“max=%c\n”,max);

min=a;

if(min&gt;b)min=b;

< p>if(min&gt;c)min=c;

printf(“min=%d\n”,min);

}

Expanded Information

The source code to find out and print the character with the largest ASCII code is as follows

#include&lt. stdio.h>

voidmain()

{

chara,b,c,max;

scanf(“%c%c%c%c”,&a,&b,&c);//reads in three characters such as abc

max=a;// Initialize max to the first

if(b>max)max=b;//compare with the second if the second is greater than max, b is assigned to max

if(c>max)max=c;//same as above

printf(“%c”,max);

}

Outputs the ASCII value (decimal) corresponding to each character.

Keyboard inputs a string and outputs the ASCII value (decimal) corresponding to each character.

For example:

Please input 10 characters: VeryGood!

The encrypted result is: 86, 101, 114, 121, 32, 71, 111, 111, 100, 33,

The program is as follows:

´╝╗Programming in [C]: input a character, determine and output the type of the character based on the ASCII value of the character?

main(void){

chara=getchar();

if(a>=97&&a<=122){

printf(“Character %d is in lowercase”,a);

}elseif(a>. =65&&a<=90){

printf(“Character %c is an uppercase letter”,a);

}elseif(a>=48&&a<=57){

printf(“Character %c is a number”,a);

} else{

printf(“Character %c is some other character”,a);

}

}

}