《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案
C語(yǔ)言是一種計(jì)算機(jī)程序設(shè)計(jì)語(yǔ)言。蘇小紅著寫的《C語(yǔ)言程序設(shè)計(jì)》這門教程,課后練習(xí)題的答案是什么呢?今天就讓小編來(lái)告訴你。
《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案(第二章)
2.2 #include<stdio.h>
main()
{
float x=2.5,y=2.5,z=2.5;
printf("x=%f\n",x);
printf("y=%f\n",y);
printf("z=%f\n",z);
}
《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案(第三章)
3.1(1) #include<stdio.h>
main()
{
int a=12,b=3;
float x=18.5,y=4.6;
printf("%d\n",(float)(a*b)/2);
printf("%d\n",(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\n",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\n",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\n",x,y);
}
《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案(第四章)
4.1(1) #include<stdio.h>
main()
{
char c1='a',c2='b',c3='c';
printf("a%cb%cc%c\n",c1,c2,c3);
}
4.1(2) #include<stdio.h>
main()
{
int a=12,b=15;
printf("a=%d%%,b=%d%%\n",a,b);}
4.1(3) #include<stdio.h>
main()
{
int a,b;
scanf("%2d%*2s%2d",&a,&b);
printf("%d,%d\n",a,b);}
4.2 #include<stdio.h>
main()
{
long a,b;
float x,y;
scanf("%d,%d\n",&a,&b);
scanf("%f,%f\n",&x,&y);
printf("a=%d,b=%d\n",a,b);
printf("x=%f,b=%f\n",x,y);}
《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案(第五章)
5.1 #include<stdio.h>
main()
{
float a;
printf("Innputa:");
scanf("%f",&a);
if(a>=0)
{a=a;printf("a=%f\n",a);}
else
{a=-a;printf("a=%f\n",a);}
}
5.2 #include<stdio.h>
main()
{
int a;
printf("Inputa:");
scanf("%d",&a);
if(a%2==0)
{
printf("a 是偶數(shù)");
}
else
{printf("a 是奇數(shù)");}
}
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\n",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("該方程不是一元二次方程\n");
}
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\n",x,y);
}
else if(b*b-4*a*c==0)
{
x=-b/(2*a);
y=-b/(2*a);
printf("x=%f,y=%f\n",x,y);
}
else
{printf("該方程無(wú)實(shí)根\n");}
}
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 !\n",year);}
else
{printf("%d is not a leap year !\n",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 !\n",year);
}
else
{printf("%d is not a leap year !\n",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\n",ch,ch);
}
else if(ch>='A'&&ch<='Z')
{
ch=getchar();
ch=ch+32;
printf("%c,%d\n",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 是數(shù)字字符\n");}
else if(ch>=65&&ch<=90)
{printf("ch 是大寫字母\n");}
else if(ch>=97&&ch<=122)
{printf("ch 是小寫字母\n");}
else if(ch==32)
{printf("ch 是空格\n");}
else
{printf("ch 是其他字符\n");}
}
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\n");}
if(score>=90&&score<=100)
{printf("%d--A\n",score);}
else if(score>=80&&score<90)
{printf("%d--B\n",score);}
else if(score>=70&&score<80)
{printf("%d--C\n",score);}
else if(score>=60&&score<70)
{printf("%d--D\n",score);}
else if(score>=0&&score<60)
{printf("%d- -E\n",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\n");}
else
{
switch(year,month)
{
case 12:
case 10:
case 8:
case 7:
case 5:
case 3:
case 1:
printf("31 天\n");
break;
case 11:
case 9:
case 6:
case 4:
printf("30 天\n");
break;
case 2:
if(year%4==0&&year!=0||year%400==0)
{printf("29 天\n");}
else
{printf("28 天\n");}
break;
default:
printf("Input error\n");}}}
【《C語(yǔ)言程序設(shè)計(jì)》蘇小紅著課后答案】相關(guān)文章:
1.C語(yǔ)言程序設(shè)計(jì)(蘇小紅著)課后答案下載
2.C語(yǔ)言程序設(shè)計(jì)(蘇小紅著)課后習(xí)題答案下載
3.C語(yǔ)言程序設(shè)計(jì)(蘇小紅著)課后習(xí)題答案下載
4.C語(yǔ)言程序設(shè)計(jì)(蘇小紅著)課后習(xí)題第八章答案
5.C語(yǔ)言程序設(shè)計(jì)(楊勇著)課后答案下載
6.C語(yǔ)言程序設(shè)計(jì)(陳明晰著)課后答案下載