资源描述:
《湘潭大学c语言课后习题答案》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、5.2#includevoidmain(){inta,b,c,num,n;printf("请输入一个三位数:");scanf("%d",&num);c=num%10;b=(num/10)%10;a=num/100;if(a==b&&a!=c)n=1;elseif(a==c&&a!=b)n=1;elseif(b==c&&a!=b)n=1;elsen=0;if(n)printf("%d",num);}5.3#include#includevoidmain(){intx;
2、doubley;scanf("%d",&x);/*输入x*/switch(x/10){case0:y=cos(x+3.0);break;case1:y=pow(cos(x+7.5),2);break;case2:y=pow(cos(x+4.0),4);break;}printf("%lf",y);}5.4#includevoidmain(){intnum,i,leap;scanf("%d",&num);if(num%2!=0){printf("是奇数");if(num>1){for(i=2;i<=n
3、um/2;i++){if(num%i==0){leap=0;break;}elseleap=1;}if(leap)printf("是素数");elseprintf("不是素数");}}elseprintf("是偶数");}5.5#includevoidmain(){inta,b,c,i,n;for(i=0;i<10000;i++){for(n=1;n<10000;n++){a=i;b=a+n;c=b+n;if(a*c==5*b&&b+c==8*a){printf("%d,%d,%d",a,b
4、,c);break;}}}}6.1#include#includevoidmain(){doublem=1.0,p=0.0;intk=1,n=1;do{m=1.0/n;n=n+2;if(k%2==0)m=(-1.0)*m;p=p+m;k++;}while(fabs(m)>=1e-6);p=p*4.0;printf("%lf",p);}6.2#includevoidmain(){intk,k1=1,k2=1,k3;floatp=0,m;for(k=1;k<=20;k++)
5、{k3=k1+k2;m=(float)k3/k2;p=p+m;k1=k2;k2=k3;}printf("%f",p);}6.3(1).#includevoidmain(){inti,j,k;for(i=0;i<=4;i++){for(j=0;j<=3-i;j++)printf("");for(k=0;k<=2*i;k++)printf("*");printf("");}for(i=0;i<=3;i++){for(j=0;j<=i;j++)printf("");for(k=0;k<=6-2*i;k++
6、)printf("*");printf("");}}(2.)#includevoidmain(){inti,j,k;charc=65;for(i=0;i<=4;i++){for(j=0;j<=3-i;j++)printf("");for(k=0;k<=2*i;k++)printf("%c",c);printf("");c=c+1;}for(i=0;i<=3;i++){for(j=0;j<=i;j++)printf("");for(k=0;k<=6-2*i;k++)printf("%c",c);pri
7、ntf("");c=c+1;}}6.4#includevoidmain(){inta,b,i,n;for(a=1;a<3000;a++){for(b=0,i=1;i<=a/2;i++)if(a%i==0)b=b+i;for(n=0,i=1;i<=b/2;i++)if(b%i==0)n=n+i;if(n==a&&a#includevoidmain(){intnum,a,b,c,p;for(num=
8、100;num<1000;num++){c=num%10;b=num/10%10;a=num/100;p=pow(a,3)+pow(b,3)+pow(c,3);if(num==p)printf("%d",num);}}6.6#includevoidmain(){int