您的当前位置:首页正文

c语言程序设计课后习题答案 第四章

2022-06-09 来源:年旅网


/*习题4 4*/

#include

main()

{

int x1,x2,i,n,x;

double item,sum;

printf(\"enter n:\\n\");

scanf(\"%d\

x1=2;x2=1;

sum=0;

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

{

item=1.0*x1/x2;

sum=sum+item;

x=x1+x2;

x2=x1;

x1=x;

}

printf(\"sum=%.2lf\\n\

}

/*练习4-3*/

#include

#include

main()

{ int a=-1,t=-2;

double eps,s=0,item=1;

printf(\"enter eps:\\n\");

scanf(\"%lf\

while(fabs(item)>=eps)

{

t=t+3;

a=-a;

item=a*1.0/t;

s=s+item;

}

printf(\"s=%lf\\n\

}

/*练习4-3*/

#include

main()

{ int n=-1,bujige=-1;

double grade=0,sum=0,ave;

printf(\"enter grade:\\n\");

while(grade>=0)

{

sum=sum+grade;

if(grade<60)

bujige=bujige+1;

n=n+1;

scanf(\"%lf\

}

ave=sum/n;

printf(\"ave=%lf\\n\

printf(\"bujige=%d\\n\

}

/*练习4-4*/

#include

main()

{ int n=-1,bujige=-1;

double chengji=0,sum=0,ave;

printf(\"enter n ge zheng zheng shu \\n\");

while(chengji>=0)

{

sum=sum+chengji;

n++;

if(chengji>=0&&chengji<=60)

bujige=bujige+1;

scanf(\"%lf\

}

ave=sum/n;

printf(\"ave=%lf\\n\

printf(\"bujige=%d\\n\

}

/*练习4-7*/

#include

main()

{ int n,i,j,m;

printf(\"enter zheng zheng shu n:\\n\");

scanf(\"%d\

printf(\"enter n ge zheng zheng shu:\\n\");

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

{scanf(\"%d\

if(m==1)

printf(\"1 bu shi su shu \\n\");

else

{ for(j=2;j<=m/2;j++)

if(m%j==0)

break;

if(j>m/2)

printf(\"%d shi su shu\\n\

else

printf(\"%d bu shi su shu\\n\

}

}

}

/*练习4-8*/

#include

main()

{ int n,i,j,jiecheng;

double sum=0;

printf(\"enter yi ge zheng zheng shu n:\\n\");

scanf(\"%d\

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

{ jiecheng=1;

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

jiecheng=jiecheng*j;

sum=sum+1.0/jiecheng;

}

printf(\"e=%.2lf\\n\

}

/*练习4-11*/

#include

main()

{ int n,mark,i,min;

printf(\"enter yi ge zheng zheng shu n:\\n\");

scanf(\"%d\

printf(\"enter n ge zheng shu\\n\");

scanf(\"%d\

min=mark;

for(i=1;i<=n-1;i++)

{ scanf(\"%d\

if(markmin=mark;

}

printf(\"min=%d\\n\

} printf(\"min=%d\

}

#include

#include

main()

{ int m;

printf(\"enter yi ge zheng shu:\\n \");

scanf(\"%d\

m=fabs(m);

while(m!=0)

{printf(\"%d\

m=m/10;

}

printf(\"\\n\");

}

/*习题4-13*/

#include

main()

{ int i,j,sum=1;

for(i=100;i<=200;i++)

{for(j=2;j<=i/2;j++)

if(i%j==0)

break;

if(j>i/2)

{ printf(\"%6d\

sum=sum+1;}

if(sum>8)

{ printf(\"\\n\");

sum=1;

}

}

printf(\"\\n\");

}

/*习题4-14*/

#include

main()

{

int x1=1,x2=1,i,x;

printf(\"%6d%6d\

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

{

x=x1+x2;

printf(\"%6d\

x1=x2;

x2=x;

}

printf(\"\\n\");

}

/***/

#include

main()

{ int i,j,k;

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

{

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

printf(\" \");

for(k=1;k<=2*i-1;k++)

printf(\"*\");

printf(\"\\n\");

}

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

{

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

printf(\" \");

for(k=1;k<=7-2*i;k++)

printf(\"*\");

printf(\"\\n\");

}

}

因篇幅问题不能全部显示,请点此查看更多更全内容