当前位置:首页 » 编程语言 » c语言习题及实验指导

c语言习题及实验指导

发布时间: 2023-03-14 15:49:35

‘壹’ 急需!!!<c语言程序设计习题解析与实验指导>函数编程练习 实验5 题2 答案

1、
#include "stdio.h"
void print(int array[],int length){
int i;
clrscr();
for(i=0;i<length;i++)printf("%d ",array[i]);
}
main(){
int array[5]={6,8,4,9,5};
print(array,5);
getchar();
}
2、
#include "stdio.h"
double average(int array[],int length){
int i;
double total=0,average=0;
for(i=0;i<length;i++)
total=total+array[i];
average=total/length;
return average;
}
main(){
int array[5]={6,8,5},i;
clrscr();
printf("The average is %0.8f",average(array,3));
getchar();
}
3、
#include "stdio.h"
int getmax (int array[],int length){
int max=array[0],i;
for(i=0;i<length;i++)if(max<array[i])max=array[i];
return max;
}
main(){
int array[5]={6,8,4,9,5};
clrscr();
printf("The max is %d",getmax(array,5));
getchar();
}
4、
#include "stdio.h"
int retrieve(int array[],int length,int x){
int i;
for(i=0;i<length;i++)if(array[i]==x)break;
if(i<length)return i+1;/*返回x在该数组中的位置*/
else return -1;/*没查找到*/
}
main(){
int array[5]={6,8,4,9,5},x=5;
int order = retrieve(array,5,x);
clrscr();
if(order==-1)printf("%d is not in this array!",x);
else printf("The order of %d in this array is %d",x,order);
getchar();
}
5、
#include "stdio.h"
void sort(int array[],int length){/*选择排序法*/
int i,j,max,k,x;
for(i=0;i<length-1;i++){
max=i;
for(j=i;j<length;j++)
if(array[max]<array[j])max=j;
if(max!=i){k=array[i];array[i]=array[max];array[max]=k;}
}
clrscr();
for(i=0;i<length;i++)printf("%d ",array[i]);
}
main(){
int array[5]={6,8,4,9,5};
sort(array,5);
getchar();
}

‘贰’ 求孙亚飞主编的C语言程序设计的课后答案啊啊

网络有很多这个教程的答案,非常多。你自己根据需求去下《C语言程序设计实验指导与习题解答》是与孙力主编的《C语言程序设计》(中国农业出版社出版)配套使用的实验指导书。全书共有4章。第1章是C语言编译环境介绍,主要介绍了VisualC++6.0集成开发环境下编辑、编译、调试和运行程序的方法。第2章是上机实验内容,编写了配合《C语言程序设计》上机实验的47个实验和1个综合实训,实验内容循序渐进,由浅入深,分别由基础性实验、提高性实验、综合性和设计性实验构成。第3章是程序开发中的常见错误与调试。第4章是《C语言程序设计》每章末部分习题的参考答案。

‘叁’ c语言程序设计实验与习题指导颜晖主编第三版答案,有的私信我

1、求1+2+3+……….+100。(循环)答案#includevoidmain(){inti,sum=0;for(i=1;ivoidmain(){inta,b,c,d;scanf("%d,%d,%d",&a,&b,&c);d=max(a,b,c);printf("max=%d",d);getch();/*暂停看运行结果*/}intmax(intx,inty,intz){intu;if(x>=y&&x>=z)u=x;elseif(y>=x&&y>=z)u=y;elseu=z;return(u);4.用起泡法对十个数据排序(数组实现)答案#includemain(){inti,j,t;staticinta[10]={5,7,4,2,3,6,1,0,9,8};for(j=0;ja[i+1]){t=a[i];a[i]=a[i+1];a[i+1]=t;}}}for(i=0;imain(){inta[10],i=0;for(i=0;i=0;i--)printf("%f",a[i]);}6输入两个数,交换他们的值并输出。(元素交换)答案#includeintmain(){intm,n,temp;scanf("%d%d",&m,&n);if(mvoidmain(){inti=1;for(i;i='a')a[i]=a[i]-32;printf("%c",a[i]);}printf("\n小写为:");for(i=0;i=65&&c=97&&c=48&&c=100&&xvoidmain(){charc;while((c=getchar())!='\n'){c=c+4;if(c>'Z'+4||c>'z')c=c-26;}printf("%c",c);}printf("\n");}12,P1115.55.6(switch)5.5#includemain(){intx,y;printf("输入x:");scanf("%d",&x);if(xmain(){floatscore;chargrade;case2:printf("请输入学生成绩:");scanf("%f",&score);while(score>100||(scorevoidmain(){intyear,leap;scanf("%d",&year);if(year%4==0){if(year%100==0){if(year%400==0)leap=1;elseleap=0;}elseleap=1;}elseleap=0;if(leap)printf("%dis",year);elseprintf("%disnot",year);printf("aleapyear.\n")}5.614,P31例2.17例2.182.17输出50个学生中成绩高于80分者的学号和成绩2.18输出2000——2500年每一年是否闰年#includevoidmain(){intyear;year=2000;go:if(((year%4==0)&&(year%100!=0))||(year%400==0))printf("%disrunnian",year);if(year2500)gotoend;gotogo;end:getch();}希望对你有所帮助

‘肆’ C语言程序设计教程实验指导六 函数 修改为正确程序

结构如下:
#include<stdio.h>
int main()
{
int y;
printf("%d\n",sum(y));
}
int sum(int a)
{
int b;
scanf("%d",&b);
return(a+b);
}

‘伍’ 急需c语言程序设计教程第四版实验指导与习题解答课后习题答案,谢谢!!

你把这个拿去试试,我到网上找了一个帮你改的,看看可以不,

#include<stdio.h>
int main()
{
//int a[10][10];
int n;
printf("please input the line:\n");
scanf("%d\n",&n);
getchar();
int i,j;
for(i=0;i<n;i++)
{
a[i][0]=1;
a[i][i]=1;
}
for(i=2;i<n;i++)

for(j=1;j<i;j++)

a[i][j]=a[i-1][j-1]+a[i-1][j];

for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
printf("%d ",a[i][j]);
printf("\n");

}
return 0;
}

‘陆’ 求c语言程序设计第三版和c语言程序设计实验与习题指导答案

c语言程序设计第三版指导答案

附录F课后题参考答案
习题1
1.1填空题
1.函数
2.主函数main();主函数main()3.主函数main()4.函数首部;函数体5.{;}
6.顺序结构;选择结构;循环结构7..c;.obj;.exe
1.2思考题
1.答:结构化程序设计是指,为使程序具有一个合理的结构以保证程序正确性而规定的一套如何进行程序设计的原则。顺序结构,选择结构,循环结构
2.答:算法是对具体问题求解步骤的一种描述。计算机算法的表达工具通常采用以下几种方法:①用自然语言表示算法;②用流程图表示算法;③用伪代码表示算法;④用程序设计语言表示算法。
3.略4.略5.略1.3编程题1.答:
#include"stdio.h"main()
{floata=10,b=20,h=5,s;s=(a+b)*h/2;
printf("s=%f",s);}
2.答:
#include"stdio.h"
main()
{printf("******************************");printf("*helloworld*");printf("******************************");}
习题2
2.1单选题
DBDCADCABBCA
2.2填空题
1.2.000000

2.1;0.500000
3.9;24.65.100;d6.(1)20
(2)0

(3)607.(1)10;6;4
(2)6;9;15
(3)3;60;83
8.55或'7'
9.x=4;y=6;z=3;m=463
2.3改错题(略)
习题3
3.1单选题
BDABCADCACBBA
3.2填空题
1.32.2613.10
4.2,1;互换a,b的值5.6.66.0037.7
8.5.0,4,c=3<Enter>
9.i=10,j=20<Enter>
10.(1)65(2)65,A(3)3.14,123.46
(4)3.141600e+000,1.234560e+002(5)8765.432100(6)8.765432e+003
11.a=2b=5x=8.8y=76.34c1=65c2=9712.%d/%d;%d/%d=%.2f
3.3改错题(略)3.4编程题
1.答:
#include"stdio.h"main(){
intx,y;
scanf("%d%d",&x,&y);printf(" x y ");
printf("十进制数 %d %d ",x,y);printf("八进制数 %o %o ",x,y);printf("十六进制数 %X %x ",x,y);}
2.答:
#include"stdio.h"main(){
charch;
printf("请输入一个大写英文字母");scanf("%c",&ch);
printf("大写英文字母是%c ",ch);printf("它的前导字符是%c ",ch-1);printf("它的后续字符是%c ",ch+1);}
3.答:
#include"stdio.h"main(){
intx,a,b,c,y;
printf("请输入一个三位整数 ");scanf("%d",&x);a=x/100;
b=(x-a*100)/10;c=x%10;
y=c*100+b*10+a;
printf("反向输出该整数:%d ",y);}}
4.答:
#include"stdio.h"main()
{inthour;
doublesalary,salaryday;
scanf("%d,%lf",&hour,&salaryday);
salary=hour*salaryday-hour*salaryday*0.1;
printf("%8.2lf ",salary);}
5.答:
#include"stdio.h"main(){
inta,b,c,t;
printf("请输入三个整数 ");scanf("%d%d%d",&a,&b,&c);
printf("交换前a=%d,b=%d,c=%d ",a,b,c);t=a;a=c;c=b;b=t;
printf("交换后a=%d,b=%d,c=%d ",a,b,c);}
习题4
4.1单选题
BADDDACBBBBA
4.2填空题
1.1
2.(1)a>0||b>0
(2)x>0&&x<=10(3)a==1.5&&b==1.5&&c==1.5
(4)p<a||p<b||p<c
3.(1)0(2)1(3)1(4)0(5)1
4.c=15.-46.17.5,0,38.59.123
10.(cvb=='y'||cvb=='Y')&&(work>=3||college=='y'||college=='Y')&&age<=35
4.3改错题(略)4.4编程题
1.答
#include"stdio.h"
#include"math.h"main(){
doublea,b,c,p,area;
scanf("%lf%lf%lf",&a,&b,&c);
printf("三角形的三边为:%.llf,%.1lf,%.1lf ",a,b,c);if(a+b>c&&a+c>b&&b+c>a){p=(a+b+c)/2;
area=sqrt(p*(p-a)*(p-b)*(p-c));
printf("三角形的面积为%.2lf ",area);}else
printf("不能构成三角形 ");}
2.答:
#include"stdio.h"main()
{intx,y;
scanf("%d,%d",&x,&y);if(x*x+y*y>1000)
printf("%d ",(x*x+y*y)/100);else
printf("%d ",x+y);}
3.答:
#include"stdio.h"#include"math.h"main()
{doublex,y;
scanf("%lf",&x);if(x<-2)y=x*x-sin(x);elseif(x<=2)y=pow(2,x)+x;elsey=sqrt(x*x+x+1);
printf("x=%.2lfy=%.2lf ",x,y);}
4.答:
#include"stdio.h"main()
{longge,shi,qian,wan,x;scanf("%ld",&x);wan=x/10000;
qian=x%10000/1000;shi=x%100/10;
ge=x%10;
if(ge==wan&&shi==qian)/*个位等于万位并且十位等于千位*/printf("thisnumberisahuiwen ");else
printf("thisnumberisnotahuiwen ");
}
5.答:
#include"stdio.h"main()
{floatp,w,s,d,f;
scanf("%f,%,%f",p,s,w);if(s>3000)d=0.15elseif(s>=2000)d=0.1;elseif(s>=1000)d=0.08;elseif(s>=500)d=0.05;elseif(s>=250)d=0.02;elsed=0f=p*w*s*(1-d);printf("%f",f);}
6.答:
#include"stdio.h"main()
{intyear,money;charx;
printf("是否是本公司产品(y/n):");scanf("%c",&x);
if(x=='y'||x=='Y')
{printf("产品使用的年限:");scanf("%d",&year);
if(year<=1)money=0;
elseif(year<8)money=50;elsemoney=100;

printf("产品保修额是:%d ",money);
}
else
{money=200;
printf("不是本公司产品,产品保修额是:%d ",money);}}
7.答:
#include"stdio.h"main()
{intmoney,num1,num2;
printf("请输入取款额(≤2000):");scanf("%d",&money);
if(money>2000)printf("请输入取款额数≤2000! ");elseif(money%50==0){num1=money/100;num2=(money-num1*100)/50;printf("需支付100元:%d张 ",num1);printf("需支付50元:%d张 ",num2);}elseprintf("输入钱数必须是50的倍数! ");}
习题5
5.1单选题
CDABAABDDBDBCB
5.2填空题
1.202.333
3.(1)i<10或i<=9(2)j%3!=0
4.(1)flag*(float)k/(k+1)或1.0*flag*k/(k+1)(2)flag=-flag5.(1)max=x


(2)x!=-1(3)scanf("%d",&x)
6.(1)x<=9或x<10
(2)y=9-x
5.3改错题(略)5.4编程题
1.答:
(1)for循环,其他略
#include"stdio.h"
main()
{inti,s=0;
for(i=1;i<=100;i++)s+=i*i;
printf("%d ",s);}
(2)for循环,其他略
#include"stdio.h"main()
{inti=1,p=1;doubles=1;do{
s+=1.0/p;p*=++i;
}while(1.0/p>1e-6);printf("%lf",s);}
2.答:
#include"stdio.h"main()
{intm,n,t,a,b;
scanf("%d,%d",&m,&n)if(m<n)
{t=mm=nn=t}a=m;b=n;t=m%nwhile(t)
{m=nn=tt=m%n;}printf("%d",n);}
3.答:
#include"stdio.h"main()
{intx,y,s=1;
scanf("%d,%d",&x,&y)for(y>0y--)s*=x
printf("%d,%d,%d ",s%10,s/10%10,s/100%10);}
4.答:
#include"stdio.h"main()
{intx,y,z;
for(x=1x<20x++)for(y=1y<33y++){z=100-x-y
if((z%3)==0&&(5*x+3*y+z/3)==100)printf("x=%d,y=%d,z=%d ",x,y,z)}}
5.答:(a)
#include"stdio.h"main()
{intj,k
for(j=1j<=4j++)
{for(k=1;k<=4-j;k++)printf("");printf("****")printf(" ")}}
(b)
#include"stdio.h"main()
{intj,k
for(j=1j<=4j++)
{for(k=1;k<=4-j;k++)printf("");for(k=1k<=2*j-1k++)printf("*")printf(" ")}}
6.答:
程序分析:利用for循环控制在100~999之间,对每个数分解出个位、十位、百位。
#include<stdio.h>main(){inti,j,k,n;printf("waterflower'numberis:");for(n=100;n<1000;n++){i=n/100;/*分解出百位*/j=n/10%10;/*分解出十位*/k=n%10;/*分解出个位*/if(n==i*i*i+j*j*j+k*k*k){printf("%-5d",n);}}printf(" ");}
7.答:
#include<stdio.h>main(){intx;for(x=1000;x>=3;x--)if(x%3==1&&x%5==2&&x%7==3){
printf("该校的学生人数是:%d人 ",x);break;}}
8.答:
#include<stdio.h>main(){intx=12,i=1;while(1)
{if((x+20+i)==2*(x+i))break;i++;}printf("小明母亲在%d年后比小明的年龄大一倍 ",i);printf("那时小明年龄是:%d岁,小明母亲年龄是:%d岁 ",x+i,x+20+i);}
习题6
6.1单选题
DBCCBBDC
C语言程序设计教程(第3版)
278
6.2填空题
1.c2.603.1000104.16
6.3编程题
1.答:
#include"stdio.h"#include"math.h"
#defineF(a)a*a+sqrt(3*a*a+2*a+1)main()
{floatx,f;
scanf("%f",&x);
f=4.5/F(exp(x))+F(cos(x))+F(sqrt(x))/F(x*x)printf("%f ",f);}
习题7
7.1单选题
BCADACCCDABCBDB
7.2填空题
1.(1)2345(2)10010(3)QuickC

(4)1000001000001000001000001(5)Language
(6)LanguageProgramming2.(1)j+=2(2)a[i]>a[j]3.(1)i=1(2)x[i-1]
7.3改错题(略)7.4编程题
1.答:
#defineN10
#include"stdio.h"main()
{inta[N]={1,2,3,4,5,6,7,8,9,10,osum=0,qsum=0,j;for(j=0;j<10;j++)
if(j%2)qsum+=a[j];
elseosum+=a[j];
printf("osum=%d,qsum=%d ",osum,qsum);}
2.答:
#defineN10
#include"stdio.h"main()
{inta[N]={10,20,30,40,50,60,70,80,90},j,k,x;scanf("%d",&x);for(j=0;j<N;j++)
if(x<a[j])break;if(j==N)a[N-1]=x;else
{for(k=N-1;k>j;k--)a[k]=a[k-1];a[j]=x;}
for(j=0;j<N;j++)
printf("%d",a[j]);}
3.答:
#defineM3
#include"stdio.h"main()
{inta[M][M]={{1,2,3},{2,4,5},{3,5,6}},j,k,flag=1;;for(j=0;j<M;j++)
for(k=0;k<M;k++)if(a[j][k]!=a[k][j]){flag=0;break;}if(flag)printf("ok");elseprintf("NO");}
4.答:
#include"stdio.h"#include"string.h"main()
{charc1[10],c2[10],j;gets(c1);gets(c2);
for(j=0;(c1[j]==c2[j])&&c1[j]&&c2[j];j++);if(c1[j]>c2[j])printf("%d ",1);if(c1[j]<c2[j])printf("%d ",-1);if(c1[j]==c2[j])printf("%d ",0);}
5.答:
#include"stdio.h"#include"string.h"#defineM3#defineN80main()
{chara[M][N],j,k,n[5]={0};for(j=0;j<M;j++)gets(a[j]);
for(j=0;j<M;j++)
for(k=0;a[j][k];k++)
if(a[j][k]>='A'&&a[j][k]<='Z')n[0]++;
elseif(a[j][k]>='a'&&a[j][k]<='z')n[1]++;elseif(a[j][k]>='0'&&a[j][k]<='9')n[2]++;elseif(a[j][k]=='')n[3]++;elsen[4]++;
for(j=0;j<5;j++)printf("%4d",n[j]);}
习题8
8.1单选题
DBDACBACCC
8.2填空题
1.(1)2,1(2)10#30#(3)FOUR,P(4)60
2.(1)49
(2)2
(3)2

(4)

(5)
8.3改错题(略)8.4编程题
1.答:
#include"stdio.h"
main()
{intn1,n2,n3,t;int*p1,*p2,*p3;
printf("pleaseinput3number:n1,n2,n3:");scanf("%d,%d,%d",&n1,&n2,&n3);p1=&n1;
p2=&n2;p3=&n3;
if(*p1>*p2){t=*p1;*p1=*p2;*p2=t;}
if(*p1>*p3){t=*p1;*p1=*p3;*p3=t;}if(*p2>*p3){t=*p2;*p2=*p3;*p3=t;}
printf("thesortednumbersare:%d,%d,%d ",n1,n2,n3);}
2.答:
#include"stdio.h"#defineN3main()
{inta[N],*p=a;for(;p-a<N;p++)scanf("%d",p);p=a+N-1;
for(;p-a>=0;p--)printf("%d",*p);}
3.答:
#include"stdio.h"main()
{inta[10];
intj,minl=0,maxl=0;for(j=0;j<10;j++)
scanf("%d",a+j);for(j=0;j<10;j++)
{if(a[maxl]<*(a+j))maxl=j;if(a[minl]>*(a+j))minl=j;}
j=a[0];a[0]=a[minl];a[minl]=j;j=a[9];a[9]=a[maxl];a[maxl]=j;for(j=0;j<10;j++)printf("%d",*(a+j));}
4.答:
输入阵列如下:123456789101112输出阵列如下:
121110987654321
#defineM3
#defineN4
#include"stdio.h"main()
{inta[M][N]={1,2,3,4,5,6,7,8,9,10,11,12},k,j,*p=&a[0][0],t;for(k=0,j=M*N-1;k<j;k++,j--)
{t=*(p+k);*(p+k)=*(p+j);*(p+j)=t;}for(k=0k<Mk++){for(j=0j<Nj++)
printf("%4d",a[k][j]);printf(" ");
}}
5.答:
#include"stdio.h"main(){
intlen;
charstr[20],*p=str;
printf("pleaseinputastring: ");scanf("%s",str);len=0;
while(*p!=''){
len++;p++;}
printf("thestringhas%dcharacters. ",len);}
6.答:
#include"string.h"#include"stdio.h"main(){
char*str1[5],ch[5][20],k,t,j,*c;voidsort(char**);for(k=0;k<5;k++){str1[k]=ch[k];gets(str1[k]);}for(k=0;k<7;k++)
{t=k;
for(j=k+1;j<5;j++)if(strcmp(*(str1+t),*(str1+j))>0)t=j;c=*(str1+t);
*(str1+t)=*(str1+k)*(str1+k)=c}
for(k=0;k<5;k++)puts(str1[k]);}
习题9
9.1单选题
CBBADDBCCDDCABCBCCBADCDAB
9.2填空题
1.1202.x3.3,2,2,34.fac/i5.8,176.97.1.0/(i*i)8.
fun-in:30,20,10fun-end:1015,35,105010,20,309.01234510.9363611.(1)r+b[k](2)*x
12.7531913.15
14.(1)*x(2)t15.(1)''(2)n++16.024
9.3改错题(略)9.4编程题
1.答:
voidzhuan()
{charch;
while((ch=getchar())!=' ')
{if(ch>='a'&&ch<='z')ch=ch-32;putchar(ch);}}
2.答:
doubleexpp(intn){intk,fac=1;doublesum=1;
for(k=1;k<=n;k++){fac*=k;
sum+=1.0/fac}
return(sum);}
3.答:
intxy3(intx,inty)
{intk,num=1;
for(k=1;k<=yk++)num*=x
num=num%1000returnnum}
4.答:
intage(intn){intc;
if(n==1)c=10
elsec=age(n-1)+2returnc}
5.答:
#include"stdio.h"
main()
{inta,b,c,d;
voidfun(inta,intb,int*c,int*d);scanf("%d%d",&a,&b);fun(a,b,&c,&d);
printf("%d%d",c,d);
}
voidfun(inta,intb,int*c,int*d){if(b)
{*c=a/b;*d=a%b;}}
6.答:
#include"stdio.h"
main(intargc,char*argv[]){intk;
printf("argc=%d ",argc);for(k=1;k<argc;k++)printf("%s ",argv[k]);}
习题10
10.1单选题
CDBBBBBBADCCBDC
10.2填空题
1.所有结构体成员所占存储空间的总和2.与占用存储空间最大的那个成员相等
附录F课后题参考答案

285
3.(1)structsatype(2)3(3)sa.a(4)9(5)psa=&sa4.805.structnode6.0
10.3编程题
1.答:
#include"stdio.h"
structstudent{
longnum;
charname[20];charsex;floatscore;};main()
{structstudents[20],temp;intj,k,man=0,woman=0;
floatsumman=0,sumwoman=0,aveman,avewoman;for(k=0;k<20;k++)
{scanf("%ld%s%c%f",&s[k].num,s[k].name,&s[k].sex,&s[k].score);if(s[k].sex=='m')
{summan+=s[k].score;man++;}else
{sumwoman+=s[k].score;woman++}}
aveman=summan/man;
avewoman=sumwoman/woman;
printf("%d %f %d %f ",man,aveman,woman,avewoman);for(k=0;k<19;k++)
for(j=0;j<20-k;j++)
if(s[j].score<s[j+1].score)
{temp=s[j];s[j]=s[j+1];s[j+1]=temp;}printf("thesortednumbers: ");for(k=0;k<20;k++)
printf("%ld %s %c %5.1f ",s[k].num,s[k].name,s[k].sex,s[k].score);}
习题11
11.1单选题
BADD
11.2填空题
1.3d3d3302.(1)28
(2)20(3)0(4)--9
3.(1)251
(2)42
(3)209
(4)–295(5)848
习题12
12.1单选题
BCDCAADA
12.2填空题
1.rewind(文件指针)2."d1.dat","rb"3.stdin
4.文本文件;二进制文件5.(1)"w"
(2)str[i]--32

(3)"r"
6.fopen7.Hello8.(1)"r"

(2)fgetc(fp)

(3)time++


C语言程序设计实验与习题指导课后程序设计答案
P18
(1)
#include<stdio.h>intmain(void){intcelsius,fahr;fahr=150;celsius=5*fahr/9-5*32/9;printf("fahr=%d,celsius=%d ",fahr,celsius);return0;}
(2)
#include<stdio.h>intmain(void){intcelsius,fahr;celsius=26;fahr=9*celsius/5+32;printf("celsius=%d,fahr=%d ",celsius,fahr);return0;}
(3)
#include<stdio.h>intmain(void){intaverage,math,eng,comp;math=87;eng=72;comp=93;average=(math+eng+comp)/3;printf("math=%d,eng=%d,comp=%d,average=%d ",math,eng,comp,average);return0;}
(4)
#include<stdio.h>intmain(void){intn,a,b,c;n=152
c=n%10;
b=(n/10)%10;a=n/100;
printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d ",n,c,b,a);return0;
}
P27
(1)
#include<stdio.h>#include<math.h>intmain(void){intcelsius,fahr;printf("Entercelsius:");scanf("%d",&celsius);fahr=9*celsius/5+32;printf("fahr%d ",fahr);return0;}
(2)
#include<stdio.h>#include<math.h>intmain(void){intmoney,year;doublerate,interest;printf("Entermoney,year,rate:");scanf("%d%d%lf",&money,&year,&rate);interest=money*pow(1+rate,year)-money;printf("interest=%.2f ",interest);return0;}
(3)
#include<stdio.h>#include<math.h>intmain(void){doublex,y;printf("Enterx:");scanf("%lf",&x);
if(x<0){y=pow(x+1,2)+2*x+1/x;}else{y=sqrt(x);}
printf("y=f(%f)=%.2f ",x,y);return0;
}
(4)
#include<stdio.h>intmain(void){intx,y;printf("Enternum1:");scanf("%d",&x);printf("Enternum2:");scanf("%d",&y);printf("%d+%d=%d ",x,y,x+y);printf("%d-%d=%d ",x,y,x-y);printf("%d*%d=%d ",x,y,x*y);printf("%d/%d=%d ",x,y,x/y);printf("%d%%%d=%d ",x,y,x%y);return0;}
10的阶乘
#include<stdio.h>intmain(void){inti,n,proct;printf("Entern:");scanf("%d",&n);proct=1;for(i=1;i<=n;i++){proct=proct*i;}printf("proct=%d ",proct);return0;}

‘柒’ c语言程序设计课后习题解答与实验指导

#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
int aver(int x ,int y,int z)
{
int t;
t=(x+y+z)/3;
return(t);
}
void main()
{ int x,y,z,a,b,c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("%d,%d,%d\n",a,b,c);
}
建议改成:
#include<stdio.h>
int max(int x,int y,int z)
{
int t;
t=x>y?x:y;
t=t>z?t:z;
return(t);
}
int min(int x ,int y,int z)
{
int t;
t=x<y?x:y;
t=t<z?t:z;
return(t);
}
float aver(int x ,int y,int z)
{
int t;
t=(float)((x+y+z)/3.0);
return(t);
}
void main()
{ int x,y,z,a,b;float c;
scanf("%d,%d,%d",&x,&y,&z);
a=(*max)(x,y,z);
b=(*min)(x,y,z);
c=(*aver)(x,y,z);
printf("max=%d\nmin=%d\naver=%g\n",a,b,c);
}

热点内容
动态规划01背包算法 发布:2024-11-05 22:17:40 浏览:849
nasm编译器如何安装 发布:2024-11-05 22:01:13 浏览:180
登录密码在微信的哪里 发布:2024-11-05 22:00:29 浏览:739
c防止反编译工具 发布:2024-11-05 21:56:14 浏览:247
安卓虚拟机怎么用 发布:2024-11-05 21:52:48 浏览:344
php时间搜索 发布:2024-11-05 20:58:36 浏览:478
燕山大学编译原理期末考试题 发布:2024-11-05 20:13:54 浏览:527
华为电脑出现临时服务器 发布:2024-11-05 20:05:08 浏览:408
斗战神免费挖矿脚本 发布:2024-11-05 19:53:25 浏览:665
网吧服务器分别是什么 发布:2024-11-05 19:45:32 浏览:392