正在加载图片...
3.14编写程序,从键盘输入一个字符,求出与该字符前后相邻的两个字符,按从小到 大的顺序输出这三个字符的 ASCII码 解: ASCIi码的大小关系与字符的大小关系一致,且相邻字符的ASCI码编码连续。用顺 序结构即可实现,程序如下 #includestdio. h> maino char ch. h=getchar printf(%c ASCII code is %d\n, ch-1, ch-1) printf("%c ASCII code is %d\n", ch, ch) printf( %c ASCII code is %d\n", ch+, ch+1) 3.15编写程序,从键盘输入某学生的四科成绩,求出总分和平均分,找出最高分和最 低分 解:寻找最高分和最低分的基本操作是比较当前分数和当前最高分及最低分的大小,需要 选择结构来实现,程序如下 #include<stdio. h> fl 1. a2. a3. a4, aver, sum fl min, max printf(Enter 4 scores scanf("%f%f%f%f",&a1,&a2,&a3,&a4); min=al: max=al admin min=a2 else if (a2>max) if (a3<min) else if (a3>max) max=a3 if (a4<min)3.14 编写程序,从键盘输入一个字符,求出与该字符前后相邻的两个字符,按从小到 大的顺序输出这三个字符的 ASCII 码。 解:ASCII 码的大小关系与字符的大小关系一致,且相邻字符的 ASCII 码编码连续。用顺 序结构即可实现,程序如下: #include<stdio.h> main() { char ch; ch=getchar(); printf("%c ASCII code is %d\n",ch-1,ch-1); printf("%c ASCII code is %d\n",ch,ch); printf("%c ASCII code is %d\n",ch+1,ch+1); } 3.15 编写程序,从键盘输入某学生的四科成绩,求出总分和平均分,找出最高分和最 低分。 解:寻找最高分和最低分的基本操作是比较当前分数和当前最高分及最低分的大小,需要 选择结构来实现,程序如下: #include<stdio.h> main() { float a1,a2,a3,a4,aver,sum; float min,max; printf("Enter 4 scores :"); scanf("%f%f%f%f",&a1,&a2,&a3,&a4); min=a1;max=a1; sum=a1+a2+a3+a4; aver=sum/4; if (a2<min) min=a2; else if (a2>max) max=a2; if (a3<min) min=a3; else if (a3>max) max=a3; if (a4<min)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有