C语言程序设计苏小红版答案之欧阳史创编.docx
- 文档编号:23664759
- 上传时间:2023-05-19
- 格式:DOCX
- 页数:20
- 大小:16.42KB
C语言程序设计苏小红版答案之欧阳史创编.docx
《C语言程序设计苏小红版答案之欧阳史创编.docx》由会员分享,可在线阅读,更多相关《C语言程序设计苏小红版答案之欧阳史创编.docx(20页珍藏版)》请在冰豆网上搜索。
C语言程序设计苏小红版答案之欧阳史创编
2.2#include
时间:
2021.02.10
创作:
欧阳史
main()
{
floatx=2.5,y=2.5,z=2.5;
printf("x=%f\n",x);
printf("y=%f\n",y);
printf("z=%f\n",z);
}
3.1
(1)#include
main()
{
inta=12,b=3;
floatx=18.5,y=4.6;
printf("%d\n",(float)(a*b)/2);
printf("%d\n",(int)x%(int)y);
}
3.2#include
main()
{
intx,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
#include
main()
{
floatrate=0.0225;
floatn,capital,deposit;
printf("Inputn,capital:
");
scanf("%f,%f",&n,&capital);
deposit=capital*pow(1+rate,n);
printf("deposit=%f\n",deposit);
}
3.4#include
#include
main()
{
floata,b,c;
doublex,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);
}
4.1
(1)#include
main()
{
charc1='a',c2='b',c3='c';
printf("a%cb%cc%c\n",c1,c2,c3);
}
4.1
(2)#include
main()
{
inta=12,b=15;
printf("a=%d%%,b=%d%%\n",a,b);
}
4.1(3)#include
main()
{
inta,b;
scanf("%2d%*2s%2d",&a,&b);
printf("%d,%d\n",a,b);
}
4.2#include
main()
{
longa,b;
floatx,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);
}
5.1#include
main()
{
floata;
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
main()
{
inta;
printf("Inputa:
");
scanf("%d",&a);
if(a%2==0)
{
printf("a是偶数");
}
else
{
printf("a是奇数");
}
}
5.3#include
#include
main()
{
floata,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
#include
main()
{
floata,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);
}
elseif(b*b-4*a*c==0)
{
x=-b/(2*a);
y=-b/(2*a);
printf("x=%f,y=%f\n",x,y);
}
else
{
printf("该方程无实根\n");
}
}
5.5#include
main()
{
intyear,flag;
printf("Inputayear:
");
scanf("%d",&year);
if(year%4==0&&year%400!
=0||year%400==0)
{
flag=1;
}
else
{
flag=0;
}
if(flag==1)
{
printf("%disaleapyear!
\n",year);
}
else
{
printf("%disnotaleapyear!
\n",year);
}
}
5.6#include
main()
{
intyear,flag;
printf("Inputayear:
");
scanf("%d",&year);
flag=year%400==0||year%4==0&&year%100!
=0?
1:
0;
if(flag==1&&flag!
=0)
{
printf("%disaleapyear!
\n",year);
}
else
{
printf("%disnotaleapyear!
\n",year);
}
}
5.7#include
main()
{
charch;
printf("Inputch:
");
scanf("%c",&ch);
if(ch>='a'&&ch<='z')
{
ch=getchar();
ch=ch-32;
printf("%c,%d\n",ch,ch);
}
elseif(ch>='A'&&ch<='Z')
{
ch=getchar();
ch=ch+32;
printf("%c,%d\n",ch,ch);
}
else
{
printf("%c",ch);
}
}
5.8#include
main()
{
charch;
printf("Inputch:
");
scanf("%c",&ch);
if(ch>=48&&ch<=57)
{
printf("ch是数字字符\n");
}
elseif(ch>=65&&ch<=90)
{
printf("ch是大写字母\n");
}
elseif(ch>=97&&ch<=122)
{
printf("ch是小写字母\n");
}
elseif(ch==32)
{
printf("ch是空格\n");
}
else
{
printf("ch是其他字符\n");
}
}
5.9#include
main()
{
intscore,grade;
printf("Inputscore:
");
scanf("%d",&score);
grade=score/10;
if(score<0||score>100)
{
printf("Inputerror\n");
}
if(score>=90&&score<=100)
{
printf("%d--A\n",score);
}
elseif(score>=80&&score<90)
{
printf("%d--B\n",score);
}
elseif(score>=70&&score<80)
{
printf("%d--C\n",score);
}
elseif(score>=60&&score<70)
{
printf("%d--D\n",score);
}
elseif(score>=0&&score<60)
{
printf("%d--E\n",score);
}
}
5.10#include
main()
{
intyear,month;
printf("Inputyear,month:
");
scanf("%d,%d",&year,&month);
if(month>12||month<=0)
{
printf("errormonth\n");
}
else
{
switch(year,month)
{
case12:
case10:
case8:
case7:
case5:
case3:
case1:
printf("31天\n");
break;
case11:
case9:
case6:
case4:
printf("30天\n");
break;
case2:
if(year%4==0&&year!
=0||year%400==0)
{
printf("29天\n");
}
else
{
printf("28天\n");
}
break;
default:
printf("Inputerror\n");
}
}
}
6.1
(1)#include
main()
{
inti,j,k;
charspace='';
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",space);
}
for(k=1;k<=6;k++)
{
printf("*");
}
printf("\n");
}
}
6.1
(2)#include
main()
{
intk=4,n;
for(n=0;n { if(n%2==0)continue; k--; } printf("k=%d\n,n=%d\n",k,n); } 6.1(3)#include main() { intk=4,n; for(n=0;n { if(n%2==0)break; k--; } printf("k=%d,n=%d\n",k,n); } 6.2 (1)#include main() { inti,sum=0; for(i=1;i<=101;i++) { sum=sum+i; } printf("sum=%d\n",sum); } 6.2 (2)#include main() { longi; longterm,sum=0; for(i=1;i<=101;i=i+2) { term=i*(i+1)*(i+2); sum=sum+term; } printf("sum=%ld\n",sum); } 6.2(4)#include #include main() { intn=1; floatterm=1.0,sign=1,sum=0; while(term<=-1e-4||term>=1e-4) { term=1.0/sign; sum=sum+term; sign=sign+n; n++; } printf("sum=%f\n",sum); } 6.2(5)#include #include main() { intn=1,count=1; floatx; doublesum,term; printf("Inputx: "); scanf("%f",&x); sum=x; term=x; do{ term=-term*x*x/((n+1)*(n+2)); sum=sum+term; n=n+2; count++; }while(fabs(term)>=1e-5); printf("sin(x)=%f,count=%d\n",sum,count); } 6.3#include main() { intx=1,find=0; while(! find) { if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0) { printf("x=%d\n",x); find=1; x++; } } } /*intx,find=0; for(x=1;! find;x++) { if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0) { printf("x=%d\n",x); find=1; } } }*/ 6.4#include main() { inti,n; longp=1,m=1; printf("Inputn: "); scanf("%d",&n); for(i=1;i<=n;i++) { p=i*i; m=i*i*i; printf("p=%d,m=%d\n",i,p,i,m); } } 6.5#include main() { floatc,f; for(c=-40;c<=110;c=c+10) { f=9/5*c+32; printf("f=%f\n",f); } } 6.6#include #include main() { intn; doublec=0.01875,x; do{ x=x*pow(1+c,12)-1000; n++; }while(x>0); printf("x=%d\n",x); } 6.7#include main() { intn=0; floata=100.0,c; printf("Inputc: "); scanf("%f",&c); do { a=a*(1+c); n++; }while(a<=200); printf("n=%d\n",n); } 6.8#include #include main() { intn=1,count=1; doublesum=1,term=1; while(fabs(term)>=1e-5) 时间: 2021.02.10 创作: 欧阳史
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 苏小红版 答案 欧阳 创编