b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

c语言课后答案_c语言课后答案第7章_c语言程序设计教程答案

电脑杂谈  发布时间:2017-01-10 19:17:21  来源:网络整理
c语言课后答案c语言课后答案

《C语言程序设计》

(苏小红 苏小红 王宇颖 孙志岗)

课后习题答案

高等教育出版社

免费下载地址:

完整版浏览:

第二章

2.2 #include<stdio.h>

main()

{

float x=2.5,y=2.5,z=2.5;

printf("x=%f",x);

printf("y=%f",y);

printf("z=%f",z);

}

第三章

3.1(1) #include<stdio.h>

main()

{

int a=12,b=3;

float x=18.5,y=4.6;

printf("%d",(float)(a*b)/2);

printf("%d",(int)x%(int)y);

}

3.2 #include<stdio.h>

main()

{

int x,b0,b1,b2,s;

printf("Inputx:");

scanf("%d",&x);

b2=x/100;

b1=(x-b2*100)/10;

b0=x%10;

s=b0*100+b1*10+b2;

printf("s=%d",s);

}

3.3 #include<stdio.h>

#include<math.h>

main()

{

float rate=0.0225;

float n,capital,deposit;

printf("Input n,capital:");

scanf("%f,%f",&n,&capital);

deposit=capital*pow(1+rate,n);

printf("deposit=%f",deposit);

}

3.4 #include<stdio.h>

#include<math.h>

main()

{

float a,b,c;

double x,y;

printf("Inputa,b,c:");

scanf("%f,%f,%f",&a,&b,&c);

x=(-b+sqrt(b*b-4*a*c))/(2*a);

y=(-b-sqrt(b*b-4*a*c))/(2*a);

printf("x=%f,y=%f",x,y);

}

第四章:

4.1(1) #include<stdio.h>

main()

{

char c1='a',c2='b',c3='c';

printf("a%cb%cc%c",c1,c2,c3);

}

4.1(2) #include<stdio.h>

main()

{

int a=12,b=15;

printf("a=%d%%,b=%d%%",a,b);}

4.1(3) #include<stdio.h>

main()

{

int a,b;

scanf("%2d%*2s%2d",&a,&b);

printf("%d,%d",a,b);}

4.2 #include<stdio.h>

main()

{

long a,b;

float x,y;

scanf("%d,%d",&a,&b);

scanf("%f,%f",&x,&y);

printf("a=%d,b=%d",a,b);

printf("x=%f,b=%f",x,y);}

第五章:

5.1 #include<stdio.h>

main()

{

float a;

printf("Innputa:");

scanf("%f",&a);

if(a>=0)

{a=a;printf("a=%f",a);}

else

{a=-a;printf("a=%f",a);}

}

5.2 #include<stdio.h>

main()

{

int a;

printf("Inputa:");

scanf("%d",&a);

if(a%2==0)

{

printf("a 是偶数");

}

else

{printf("a 是奇数");}

}

5.3 #include<stdio.h>

#include<math.h>

main()

{

float a,b,c,s,area;

printf("Inputa,b,c:");

scanf("%f,%f,%f",&a,&b,&c);

if(a+b>c&&a+c>b&&b+c>a)

{

s=(a+b+c)/2;

area=(float)sqrt(s*(s-a)*(s-b)*(s-c));

printf("area=%f",area);

}

else

{printf("不是三角形");}

}

5.4 #include<stdio.h>

#include<math.h>

main()

{

float a,b,c,x,y;

printf("Inputa,b,c:");

scanf("%f,%f,%f",&a,&b,&c);

if(a==0)

{

printf("该方程不是一元二次方程");

}

if(b*b-4*a*c>0)

{

x=(-b+sqrt(b*b-4*a*c))/(2*a);

y=(-b-sqrt(b*b-4*a*c))/(2*a);

printf("x=%f,y=%f",x,y);

}

else if(b*b-4*a*c==0)

{

x=-b/(2*a);

y=-b/(2*a);

printf("x=%f,y=%f",x,y);

}

else

{printf("该方程无实根");}

}

5.5 #include<stdio.h>

main()

{

int year,flag;

printf("Input a year:");

scanf("%d",&year);

if(year%4==0&&year%400!=0||year%400==0)

{flag=1;}

else

{flag=0;}

if(flag==1)

{printf("%d is a leap year !",year);}

else

{printf("%d is not a leap year !",year);}

}

5.6 #include<stdio.h>

main()

{

int year,flag;

printf("Input a year:");

scanf("%d",&year);

flag=year%400==0||year%4==0&&year%100!=0?1:0;

if(flag==1&&flag!=0)

{

printf("%d is a leap year !",year);

}

else

{printf("%d is not a leap year !",year);}

}

5.7 #include<stdio.h>

main()

{

char ch;

printf("Inputch:");

scanf("%c",&ch);

if(ch>='a'&&ch<='z')

{

ch=getchar();

ch=ch-32;

printf("%c,%d",ch,ch);

}

else if(ch>='A'&&ch<='Z')

{

ch=getchar();

ch=ch+32;

printf("%c,%d",ch,ch);

}

else

{printf("%c",ch);}

}

5.8 #include<stdio.h>

main()

{

char ch;

printf("Inputch:");

scanf("%c",&ch);

if(ch>=48&&ch<=57)

{printf("ch 是数字字符");}

else if(ch>=65&&ch<=90)

{printf("ch 是大写字母");}

else if(ch>=97&&ch<=122)

{printf("ch 是小写字母");}

else if(ch==32)

{printf("ch 是空格");}

else

{printf("ch 是其他字符");}

}

5.9 #include<stdio.h>

main()

{

int score,grade;

printf("Input score:");

scanf("%d",&score);

grade=score/10;

if(score<0||score>100)

{printf("Input error");}

if(score>=90&&score<=100)

{printf("%d--A",score);}

else if(score>=80&&score<90)

{printf("%d--B",score);}

else if(score>=70&&score<80)

{printf("%d--C",score);}

else if(score>=60&&score<70)

{printf("%d--D",score);}

else if(score>=0&&score<60)

{printf("%d- -E",score);}

}

5.10 #include<stdio.h>

main()

{

int year,month;

printf("Input year,month:");

scanf("%d,%d",&year,&month);

if(month>12||month<=0)

{printf("error month");}

else

{

switch(year,month)

{

case 12:

case 10:

case 8:

case 7:

case 5:

case 3:

case 1:

printf("31 天");

break;

case 11:

case 9:

case 6:

case 4:

printf("30 天");

break;

case 2:

if(year%4==0&&year!=0||year%400==0)

{printf("29 天");}

else

{printf("28 天");}

break;

default:

printf("Input error");}}}

第 1-5 6 7 8 9 10 12章


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-25424-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...