C语言第3章作业参考答案
C++语言基础教程(吕凤翥)第三章课后部分习题答案

第三章课后部分习题答案一、选择填空二、判断下列描述的正确性,对者划√,错者划╳。
三、分析下列程序的输出结果。
1、13.52、203、134、1 4 75、35ok!6、6 77、11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 11 6 15 20 15 6 11 7 21 35 35 21 7 18、3 1 -19、1,210、SWITCH SWAMP四、按下列要求编程,并上机调试。
1、#include <iostream>using namepsace std;void main(){int sum=0;for(int i=1;i<=100;i+=2)sum+=i;cout<<"Sum="<<sum<<endl;}2、#include <iostream>using namepsace std;void main(){for(int i=100;i>=12;i--)if(i%13==0){cout<<"100之内最大的能被整除的数是:"<<i<<endl;break;}}}3、#include <iostream>using namepsace std;int f1(int,int),f2(int,int);void main(){int a,b;cout<<"Enter a,b:";cin>>a>>b;int m=f1(a,b);cout<<"最小公倍数是:"<<m<<endl;int n=f2(a,b);cout<<"最大公约数是:"<<n<<endl;}int f1(int i,int j){int k=i*j;while(i!=j){if(i>j) i-=j;if(i<j) j-=i;}return k/i;}int f2(int i,int j){while(i!=j){if(i>j) i-=j;if(i<j) j-=i;}return i;}4、#include <iostream>using namepsace std;void main(){double a=2,b=1,sum=0,t;for(int i=1;i<=15;i++){sum+=a/b;t=a;a+=b;b=t;}cout<<"SUM="<<sum<<endl;}5、#include <iostream>using namepsace std;long fac(int );void main(){long sum=0;for(int i=1;i<=10;i++)sum+=fac(i);cout<<"1至10自然数的阶乘之和为:"<<sum<<endl;}long fac(int a){long p;if(a==0)p=1;elsep=a*fac(a-1);return p;}6、#include <iostream>#include<iomanip>using namepsace std;void main(){int n=0;for(int i=1;i<40;i++){int j=i*i;if(j>=1000)continue;if(n%8==0)cout<<endl;n++;cout<<setw(8)<<j;}cout<<endl;}7、#include <iostream>using namepsace std;void main(){int a,b,c,d,t;cout<<"输入个整数:";cin>>a>>b>>c>>d;if(a<b){t=a;a=b;b=t;}if(a<c){t=a;a=c;c=t;}if(a<d){t=a;a=d;d=t;}if(b<c){t=b;b=c;c=t;}if(b<d){t=b;b=d;d=t;}if(c<d){t=c;c=d;d=t;}cout<<"按照有大到小的顺序输出如下:\n";cout<<a<<','<<b<<','<<c<<','<<d<<endl;}8、#include <iostream>using namepsace std;void main(){int x=5,y;if(x<1)y=x;else if(1<=x&&x<10)y=x+5;elsey=x-5;cout<<"当x=5时,y= "<<y<<endl;}9、#include <iostream>using namepsace std;void main(){double a,b,c,x1,x2,d;cout<<"输入方程的个系数a,b,c :";cin>>a>>b>>c;d=b*b-4*a*a;if(fabs(a)<=le-6)cout<<"方程不是二次方程。
C语言教学与习题答案3

第3章 C语言的变量
? 3.1 变量的生存期和作用域 ? 3.2 局部变量与全局变量 ? 3.3 变量的存储与变量的作用域 ? 3.4 变量使用实例 ? 3.5 小结
3.1 变量的生存期和作用域
? 3.1.1 变量的生存期 ? 3.1.2 变量的作用域
3.1.1 变量的生存期
【例3-2】该例详细说明局部变量的用法 。
3.2.2 全局变量
? 全局变量是在函数之外定义的变量(所有函数前、各个函数之间、 所有函数后)。全局变量的作用域为从定义全局变量的位置起到 本源程序结束为止。
【例3-3】通过改写代码【例3-2】来说明全局变量的用法。
3.2.3 变量的屏蔽效果
? 在C语言中,如果在同一个源文件中,外部变量与局部变量同名, 则在局部变量的作用范围内,外部变量被“屏蔽”,即它不起作 用,这种情况称为变量的“屏蔽”。
? 3.2.1 局部变量 ? 3.2.2 全局变量 ? 3.2.3 变量的屏蔽效果
3.2.1 局部变量
? 在C语言中,变量的作用域只在一定范围内有效称之为局部变量。 在以下各位置定义的变量均属于局部变量: (1)在函数体内定义的变量,变量的作用域局限于函数体内; (2)在复合语句内定义的变量,变量的作用域局限于复合语句 内; (3)有参函数的形参也是局部变量,变量的作用域只在其所在 的函数范围内有效。
【例3-4】该Leabharlann 通过实现求两个整数之和,说明变量的屏蔽。
3.3 变量的存储与变量的作用域
? 3.3.1 变量的存储 ? 3.3.2 自动型变量 ? 3.3.3 静态变量 ? 3.3.4 外部变量 ? 3.3.5 寄存器变量 ? 3.3.6 变量存储类型小结
3.1.2 变量的作用域
c第三章课后习题答案 谭浩强

1 / 22题#include <iostream> #include <iomanip> using namespace std; int main ( ){float h,r,l,s,sq,vq,vz; const float pi=;cout<<“please enter r,h:“;cin>>r>>h; l=2*pi*r; s=r*r*pi; sq=4*pi*r*r; vq=*pi*r*r*r;vz=pi*r*r*h;cout<<setiosflags(ios::fixed)<<setiosflags(ios::right)<<setprecision(2);cout<<“l= “<<setw(10)<<l<<endl;cout<<“s= “<<setw(10)<<s<<endl;cout<<“sq=“<<setw(10)<<sq<<endl;cout<<“vq=“<<setw(10)<<vq<<endl;cout<<“vz=“<<setw(10)<<vz<<endl;2 / 22return 0; } 题#include <iostream> using namespace std; int main () {float c,f; cout<<“请输入一个xx:“;cin>>f; c=*(f-32);; cin>>score; }switch(int(score/10)) {case 10:case 9: grade=“A“;break;case 8: grade=“B“;break;case 7: grade=“C“;break;case 6: grade=“D“;break;default:grade=“E“;}cout<<“score is “<<score<<“, grade is “<<grade<<endl;3 / 22return 0; } 题#include <iostream> using namespace std; int main () {long int num; int indiv,ten,hundred,thousand,ten_thousand,place; /*分别代表个位,十位,百位,千位,万位和位数*/cout<<“enter an integer(0~99999):“;cin>>num; if (num>9999) place=5; else if (num>999) place=4; else if (num>99) place=3; else if (num>9) place=2; else place=1;4 / 22cout<<“place=“<<place<<endl;.=“<<sn<<endl;return 0; } 题#include <iostream> using namespace std; int main () {float s=0,t=1; int n;for (n=1;n<=20;n++) {t=t*n;.+20!=“<<s<<endl;return 0; } 题#include <iostream> using namespace std; int main () {int i,j,k,n; cout<<“narcissus numbers are:“<<endl;5 / 22for (n=100;n<1000;n++) {i=n/100; j=n/10-i*10; k=n_x0010_;if (n == i*i*i + j*j*j + k*k*k) cout<<n<<““;}cout<<endl; } 题#include <iostream> using namespace std; int main(){const int m=1000;.,k10 {case 1:k1=i;break;<<endl; return 0; elsecout<<n<<“is not a prime.“<<endl;return 0; }6 / 22int prime(int n) {int flag=1,i;for (i=2;i<n/2 && flag==1;i++) if (n%i==0) flag=0; return(flag); } 题#include <iostream> using namespace std; int main() {int fac(int); int a,b,c,sum=0; cout<<“enter a,b,c:“;cin>>a>>b>>c;sum=sum+fac(a)+fac(b)+fac(c);cout<<a<<“!+“<<b<<“!+“<<c<<“!=“<<sum<<endl;return 0; }int fac(int n) {int f=1;7 / 22for (int i=1;i<=n;i++) f=f*i; return f; } 题#include <iostream> #include <cmath> using namespace std; int main() {double e(double); double x,sinh; cout<<“enter x:“; cin>>x;sinh=(e(x)+e(-x))/2;cout<<“sinh(“<<x<<“)=“<<sinh<<endl;return 0; }double e(double x) {return exp(x);} 题#include <iostream>8 / 22#include <cmath> using namespace std; int main(){double solut(double ,double ,double ,double ); double a,b,c,d; cout<<“input a,b,c,d:“;cin>>a>>b>>c>>d;cout<<“x=“<<solut(a,b,c,d)<<endl;return 0; }double solut(double a,double b,double c,double d) {doublex=1,x0,f,f1; do{x0=x;f=((a*x0+b)*x0+c)*x0+d; f1=(3*a*x0+2*b)*x0+c; x=x0-f/f1; } while(fabs(x-x0)>=1e-5); return(x); }9 / 22题#include <iostream> #include <cmath> using namespace std; int main() {void godbaha(int); int n;cout<<“input n:“;cin>>n; godbaha(n); return 0; }void godbaha(int n) {int prime(int); int a,b;for(a=3;a<=n/2;a=a+2) {if(prime(a)) {b=n-a; if (prime(b)) }int prime(int m)10 / 22{int i,k=sqrt(m); for(i=2;i<=k;i++) if(m%i==0) break; if (i>k) return 1; else return 0; } 题#include <iostream> using namespace std; int main() {int x,n; float p(int,int); cout<<“input n & x:“;cin>>n>>x;cout<<“n=“<<n<<“,x=“<<x<<endl;;cout<<“P“<<n<<“(x)=“<<p(n,x)<<endl;cout<<n<<“=“<<a<<“+“<<b<<endl;}}return 0;}float p(int n,int x) {if (n==0) return(1); else if (n==1)11 / 22return(x); elsereturn(((2*n-1)*x*p((n-1),x)-(n-1)*p((n-2),x))/n); } 题#include <iostream> using namespace std; int main() {void hanoi(int n,char one,char two,char three); int m; cout<<“input the number of diskes:“;cin>>m;cout<<“The steps of moving “<<m<<“disks:“<<endl; hanoi(m,“A“,“B“,“C“);return 0; }void hanoi(int n,char one,char two,char three) <<endl;; cout<<“continu or not(Y/N)“;cin>>c;if (c==“N“||c==“n“)12 / 22flag=false; } return 0; } 题#include <iostream> using namespace std; int main(){int sum_day(int,int); int leap(int year);int year,month,day,days=0;cout<<“input date(year,month,day):“;cin>>year>>month>>day;cout<<year<<“/“<<month<<“/“<<day;days=sum_day(month,day); 数一*/if(leap(year) && month>=3) 二*//*调用函/*调用函数days=days+1;cout<<“is the “<<days<<“th day in this year.“<<endl;13 / 22return 0; }int sum_day(int month,int day),tran; tran=ch;cout<<“cipher code:“<<ch<<endl;j=0; while (j<=()){ if ((ch[j]>=“A“) && (ch[j]<=“Z“))tran[j]=155-ch[j];else if ((ch[j]>=“a“) && (ch[j]<=“z“))}cout<<“original text:“;cout<<tran<<endl; return 0; } 另一解tran[j]=219-ch[j]; tran[j]=ch[j]; elsej++;#include <iostream>14 / 22#include <string> using namespace std; int main() {int j; string ch=“I will visit China next week.“;cout<<“cipher code:“<<ch<<endl;j=0; while (j<=()){ if ((ch[j]>=“A“) && (ch[j]<=“Z“))ch[j]=155-ch[j];else if ((ch[j]>=“a“) && (ch[j]<=“z“))ch[j]=219-ch[j]; j++; }cout<<“original text:“;cout<<ch<<endl; return 0; }#include <iostream> #include <string> using namespace std;15 / 22int main() {int j;string ch=“I will visit China next week.“;cout<<“cipher code:“<<ch<<endl;j=0; while (j<=()){ if ((ch[j]>=“A“) && (ch[j]<=“Z“))ch[j]=155-ch[j];else if ((ch[j]>=“a“) && (ch[j]<=“z“))}cout<<“original text:“;cout<<ch<<endl; return 0; } 题ch[j]=219-ch[j]; j++;#include <iostream> #include <string> using namespace std; intmain()16 / 22{char s1[80],s2[40]; int i=0,j=0;cout<<“input string1:“;cin>>s1;cout<<“input string2:“;cin>>s2; while (s1[i]!=“\0“)i++;while(s2[j]!=“\0“)s1[i++]=s2[j++]; s1[i]=“\0“;cout<<“The new string is:“<<s1<<endl;return 0; } 另一解#include <iostream> using namespace std; int main() {chars1[80],s2[40]; cout<<“input string1:“;cin>>s1;17 / 22cout<<“input string2:“;cin>>s2; strcat(s1,s2);cout<<“The new string is:“<<s1<<endl;return 0; } 另一解#include <iostream> #include <string> using namespace std; int main(){ string s1=“week“,s2=“end“;cout<<“s1=“<<s1<<endl;cout<<“s2=“<<s2<<endl;s1=s1+s2;cout<<“The new string is:“<<s1<<endl;return 0; } 题#include <iostream> #include <string>18 / 22using namespace std; int main() { const int n=5; int i,j;string str[n],temp;cout<<“please input strings:“<<endl; for(i=0;i<n;i++) cin>>str[i]; for(i=0;i<n-1;i++) for(j=0;j<n-i-1;j++) if(str[j]>str[j+1]){temp=str[j];str[j]=str[j+1];str[j+1]=temp;} cout<<endl<<“sorted strings:“<<endl;for(i=0;i<n;i++) } 题#include <iostream> #include <string> using namespace std; int main() { const int n=5;19 / 22string str; for(int i=0;i<n;i++){cout<<“please input string:“;cin>>str; } 题#include <iostream> using namespace std; int main() { const n=10;int i;char a[n],temp;cout<<“please input a string:“;for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n/2;i++){temp=a[i];a[i]=a[n-i-1];a[n-i-1]=temp;} for(i=0;i<n;i++) cout<<a[i]; cout<<endl; return 0;20 / 22}if(str[0]==“A“)cout<<str<<endl;} cout<<str[i]<<endl; return 0; return 0; 题另一解#include <iostream> #include <string> using namespace std; int main() { string a; int i,n; char temp;cout<<“please input a string:“;cin>>a; n=();for(i=0;i<n/2;i++){temp=a[i];a[i]=a[n-i-1];a[n-i-1]=temp;} cout<<a<<endl; return 0; }21 / 22题#include <iostream> #include <string> using namespace std; const int n=10; string name[n]; int num[n],score[n]; int main() {int i; void input_data(); input_data();cout<<endl<<“The list of failed:“<<endl;for(i=0;i<n;i++) if(score[i]<60)cout<<name[i]<<““<<num[i]<<““<<score[i]<<endl;return 0; }void input_data() {int i;for (i=0;i<n;i++){cout<<“input name,number and score of student “<<i+1<<“:“;22 / 22cin>>name[i]>>num[i]>>score[i];} }。
C语言课后作业题参考答案

C 语言课后作业题参考答案第二章2.2 用赋值表达式表示下列计算1) c b a x y +=2) 2/5262)(lne d a x -+= 3) y X aX X=+sin cos π24) R R R R =++1111123 5)232)4(7)2(5)2(31x x x x x y ++++=参考答案:1) y=pow(x,a+pow(b,c))或者:exp((a+exp(c*log(b)))*log(x))2) x=pow(log(sqrt(a+d*d))-exp(26),5.0/2)或者:exp(5.0/2*log(log(sqrt(a+d*d))-exe(26)))3) y=sin(x)/(a*x)+fabs(cos(3.1415926*x/2))4) R=1.0/(1.0/R1+1.0/R2+1.0/R3)5) y=x/(1+(x/(3+(pow(2*x,2)/5+(pow(2*x,3)/(7+pow(4*x,2)))))))2.6 编写程序,输入两个整数,分别求它们的和、差、积、商、余数并输出。
参考答案:#include<stdio.h>void main(){int m,n;printf("请输入2个整数\n");scanf("%d%d",&m,&n);printf("%d+%d=%d\n",m,n,m+n);printf("%d-%d=%d\n",m,n,m-n);printf("%d*%d=%d\n",m,n,m*n);printf("%d 除以%d :%f\n",m,n,(float)m/n);printf("%d 除以%d 的余数:%d\n",m,n,m%n);} 2.9 已知摄氏温度C 与华氏温度F 的转换关系是)32(95-=F C ,编写一个摄氏温度与华氏温度转换的程序,输入C ,输出F.参考答案:#include<stdio.h>void main(){float f,c;printf("请输入摄氏温度的值:\n");scanf("%f",&c); //输入33//f=9*c/5+32; //结果为91.4f=9.0/5*c+32; //结果为91.4//f=9/5*c+32; //结果为65printf("转换为华氏温度是:%f\n",f);} 第3章 分支程序设计3.3 编写程序,输入一个字母,若其为小写字母,将其转换成相应的大写字母,然后输出。
C语言1 3章练习题 作业 答案

C语言1 3章练习题作业答案c语言1-3章练习题-作业-答案一、选择题(可不抄题目)1.继续执行\后,k的值就是____a.0b.3c.4d.122.以下常量中恰当的就是______a.'abc'b.'\\x123'c.3.145e-1.2d.\3.能够将高级语言撰写的源程序转换成目标程序的就是______。
a.编辑程序b.编译程序c.解释程序d.链接程序4.设a和b均为double型常量,且a=5.5、b=2.5,则表达式(int)a+b/b的值就是______。
a.6.500000b.6c.5.500000d.6.0000005.正确的c语言用户自定义标识符是______。
a.ok?b.floatc.a3bd.random26.以下程序的输入结果就是voidmain(){inta=12,b=12;printf(\,--a,++b);}a.1010b.1212c.1110d.1113二、填空题(可不抄题目)1.若存有\,则a的值就是___2.表达式a=3*5,a*4,a+5的值就是___________3.c程序已经开始往往所含以“#”结尾的命令,它们就是命令。
在程序中以“/*”已经开始,以“*/”完结的内容,它们就是程序中的部分,用来协助阅读程序。
程序代码的打印,分解成程序*.c,语法分析查错,译者分解成程序*.obj,与其它目标程序或库链接加装,分解成程序*.exe。
4.设inta;floatf;doublei;则表达式10+'a'+i*f值的数据类型是___________。
三、程序题:1、撰写一个程序,能够表明出来以下两行文字(用顺序结构顺利完成)。
2、从键盘上输入三个小数,求出平均值,并输出这三个数和平均值,要求平均值保留2位小数位数。
参考答案:一、选择题1.a2.d3.b4.d5.c6.d二、填空题1.602.203.编译预处理、注释、源、目标、可执行4.double三、程序题:1、撰写一个程序,能够表明出来以下两行文字(用顺序结构顺利完成)。
C语言课后习题参考答案

C语言课后习题参考答案第一章:基础知识问题1:C语言的发展历史及特点C语言是由贝尔实验室的肯·汤普逊和丹尼斯·里奇在20世纪70年代初开发的一种高级程序设计语言。
它以其简洁、高效和可移植性而闻名。
C语言被广泛应用于系统级编程、嵌入式系统和科学计算等领域,并成为其他编程语言的基础。
问题2:C语言的基本数据类型及其存储范围C语言的基本数据类型包括字符型(char)、整型(int)、浮点型(float)、双精度浮点型(double)和空类型(void)。
它们的存储范围如下:- char:-128 到 127 或 0 到 255- int:-32,768 到 32,767 或 0 到 65,535- float:3.4E-38 到 3.4E38- double:1.7E-308 到 1.7E308- void:无特定存储范围问题3:如何在C语言中输出语句?在C语言中,可以使用printf函数来输出语句。
它的基本语法为:```cprintf("要输出的内容");```问题4:定义变量的语法规则在C语言中,定义变量的语法规则如下:```c数据类型变量名;```例如,定义一个整型变量x:```cint x;```问题5:如何进行变量的赋值?变量的赋值可以使用赋值运算符(=)。
例如,将一个整型常量10赋值给变量x:```cx = 10;```第二章:控制结构问题1:if语句的语法结构if语句用于根据条件执行不同的代码块。
它的基本语法结构如下:```cif (条件) {// 条件为真时执行的代码}```问题2:switch语句的用法及语法结构switch语句用于根据不同的表达式值执行相应的代码块。
它的基本用法及语法结构如下:```cswitch (表达式) {case 值1:// 当表达式的值等于值1时执行的代码break;case 值2:// 当表达式的值等于值2时执行的代码break;default:// 当表达式的值与所有case都不匹配时执行的代码break;}```问题3:循环语句的分类及语法结构C语言中的循环语句包括for循环、while循环和do-while循环。
c第三章课后习题答案-谭浩强
cout<<"vq="<<setw(10)<<vq<<endl;
cout<<"vz="<<setw(10)<<vz<<endl;
return 0;
}
题
#include <iostream>
using namespace std;
int main ()
cin>>year>>month>>day;
cout<<year<<"/"<<month<<"/"<<day;
days=sum_day(month,day);
数一
*/
if(leap(year) && month>=3)
二
*//*调用函/*调用函数days=days+1;
cout<<" is the "<<days<<"th day in this year."<<endl;
case 6: grade='D';break;
default:grade='E';
}
cout<<"score is "<<score<<", grade is "<<grade<<endl;
c 第三版课后习题答案
c 第三版课后习题答案C 第三版课后习题答案C语言是一门广泛应用于计算机编程领域的编程语言,它的学习对于计算机科学和软件工程的学生来说是非常重要的。
C语言第三版是一本经典的教材,它为学生提供了丰富的习题来巩固所学的知识。
在这篇文章中,我将为大家提供C语言第三版课后习题的答案,希望能对大家的学习有所帮助。
1. 第一章:开始学习C语言在第一章中,主要介绍了C语言的基本概念和语法规则。
以下是一些常见的习题及其答案:1.1 填空题:a) C语言是一种______语言。
答案:结构化b) 在C语言中,用于存储数据的基本单元是______。
答案:变量1.2 程序设计题:编写一个C程序,要求用户输入两个整数,然后输出它们的和。
答案:```c#include <stdio.h>int main() {int num1, num2, sum;printf("请输入两个整数:");scanf("%d%d", &num1, &num2);sum = num1 + num2;printf("它们的和为:%d\n", sum);return 0;}```2. 第二章:C语言基础第二章主要介绍了C语言的基本数据类型、运算符和控制结构。
以下是一些习题及其答案:2.1 选择题:a) 下列哪个是C语言的基本数据类型?1. float2. string3. boolean4. char答案:4. charb) 下列哪个运算符用于求两个整数的商?1. +2. -3. *4. /答案:4. /2.2 程序设计题:编写一个C程序,判断一个整数是否为偶数。
答案:```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (num % 2 == 0) {printf("这是一个偶数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1 / 3
第三章
第1题:
#include
#include
int main(){float p,r,n;
r=0.1;
n=10;
p=pow(1+r,n);
printf("p=%f\n",p);
return 0;}第7题:
#include
int main (){float h,r,l,s,sq,vq,vz;
float pi=3.;
printf("请输入圆半径r,圆柱高h∶");
scanf("%f,%f",&r,&h);//要求输入圆半径r和圆柱高h
l=2*pi*r;//计算圆周xxl
s=r*r*pi;//计算圆面积s
sq=4*pi*r*r;//计算圆球表面积sq
//计算圆球体积vq
vz=pi*r*r*h;//计算圆柱体积vz
printf("圆周长为:
2 / 3
l=%6.2f\n",l);
printf("圆面积为:
s=%6.2f\n",s);
printf("圆球表面积为:
sq=%6.2f\n",sq);
printf("圆球体积为:
v=%6.2f\n",vq);
printf("圆柱体积为:
vz=%6.2f\n",vz);
return 0;}补充习题
(1)输入任意一个三位数,将其各位数字反序输出(例如输入123,输出
321)
#include
int main(){int a,b;
printf("请输入一个三位数:
");
scanf("%d",&a);
while(a>999||a<100){printf("输入错误!\n请输入一个三位数:");
scanf("%d",&a);}b=(a%10)*100+(a%100)/10*10+a/100;
printf("反序输出结果为:
%d\n",b);
3 / 3
return 0;}(2)求前驱字符和后继字符。输入一个字符,找出它的前驱字符
和后继字符,并按ASCII码值,按从大到小的顺序输出这三个字符及其对应的
ASCII码值。
#include
int main(){char a;
printf("请输入一个字符:
");
scanf("%c",&a);
printf("三个字符分别是:
%c,%c,%c\n",a+1,a,a-1);
printf("对应的ASCII码值分别是:
%d,%d,%d\n",a+1,a,a-1);
return 0;}