最新《C语言程序设计》(苏小红) 课后习题答案 高等教育出版社资料 下载本文

精品文档

case 2:

if(year%4==0&&year!=0||year@0==0) {

printf(\ 天\\n\} else {

printf(\ 天\\n\}

break; default:

printf(\ error\\n\} }

}

6.1(1)

#include main() {

int i,j,k;

char space=' '; for(i=1;i<=4;i++) {

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

printf(\}

for(k=1;k<=6;k++) {

printf(\}

printf(\} }

6.1(2) #include main() {

int k=4,n;

for(n=0;n

if(n%2==0) continue; k--; }

printf(\}精品文档

精品文档

6.1(3) #include main() {

int k=4,n;

for(n=0;n

if(n%2==0) break; k--; }

printf(\}

6.2(1) #include main() {

int i,sum=0;

for(i=1;i<=101;i++) {

sum=sum+i; }

printf(\}

6.2(2) #include main() {

long i;

long term,sum=0; for(i=1;i<=101;i=i+2) {

term=i*(i+1)*(i+2); sum=sum+term; }

printf(\}

6.2(4) #include #include main() {

int n=1;

float term=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(\

}

6.2(5) #include #include main() {

int n=1,count=1; float x;

double sum,term; printf(\ x:\scanf(\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(\}

6.3 #include main() {

int x=1,find=0; while(!find) {

if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0) {

printf(\find=1; x++; } } }

/* int x,find=0;

for (x=1;!find;x++) {

if(x%2==1&&x%3==2&&x%5==4&&x%6==5&&x%7==0) {

printf(\find=1;

精品文档

精品文档

} }

}*/

6.4 #include main() {

int i,n;

long p=1,m=1; printf(\ n:\scanf(\for(i=1;i<=n;i++) {

p=i*i; m=i*i*i;

printf(\} }

6.5 #include main() {

float c,f;

for(c=-40;c<=110;c=c+10) {

f=9/5*c+32;

printf(\} }

6.6 #include #include main() {

int n;

double c=0.01875,x; do{

x=x*pow(1+c,12)-1000; n++; }while(x>0);

printf(\

}

6.7 #include main() {

int n=0;

精品文档