C语言答案Word格式.docx

上传人:b****1 文档编号:874352 上传时间:2023-04-29 格式:DOCX 页数:16 大小:17.67KB
下载 相关 举报
C语言答案Word格式.docx_第1页
第1页 / 共16页
C语言答案Word格式.docx_第2页
第2页 / 共16页
C语言答案Word格式.docx_第3页
第3页 / 共16页
C语言答案Word格式.docx_第4页
第4页 / 共16页
C语言答案Word格式.docx_第5页
第5页 / 共16页
C语言答案Word格式.docx_第6页
第6页 / 共16页
C语言答案Word格式.docx_第7页
第7页 / 共16页
C语言答案Word格式.docx_第8页
第8页 / 共16页
C语言答案Word格式.docx_第9页
第9页 / 共16页
C语言答案Word格式.docx_第10页
第10页 / 共16页
C语言答案Word格式.docx_第11页
第11页 / 共16页
C语言答案Word格式.docx_第12页
第12页 / 共16页
C语言答案Word格式.docx_第13页
第13页 / 共16页
C语言答案Word格式.docx_第14页
第14页 / 共16页
C语言答案Word格式.docx_第15页
第15页 / 共16页
C语言答案Word格式.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

C语言答案Word格式.docx

《C语言答案Word格式.docx》由会员分享,可在线阅读,更多相关《C语言答案Word格式.docx(16页珍藏版)》请在冰点文库上搜索。

C语言答案Word格式.docx

2、[1]a%k==0[2]isprime(k+2)

第6章数组

一、1-5ADCBB

6-9BCAD

二、1、[1]a[i][2]b[j]

2、[1]&

a[i][j][2]a[i][0][3]s[i]=a[i][j]

3、[1]a[i][k]*b[k][j]

[2]c[i][j]

4、[1]%[2]/[3]j=i;

j<

=0;

j++

第7章指针

一、

1-5DADAA

11、C12、C

二、

1、[1]num=*b[2]num=*c

2、[1]i=n-1;

i>

=k;

i—

[2]a+k[3]printf(“\n”)

第8章字符数据处理

一、1-5:

AACBB

6-9:

BAAB

1、[1](*p!

=’\0’)&

(*q!

=’\0’)

[2]*p<

*q

2、[1]k

程序题答案:

(1)P53页1输出三个数,按由小到大的顺序输出。

程序如下:

#include<

stdio.h>

voidmain()

{

inta,b,c,t;

scanf(“%d%d%d”,&

a,&

b,&

c);

if(a>

b)

{t=a;

a=b;

b=t;

}

c)

t=a;

a=c;

c=t;

if(b>

t=b;

b=c;

printf("

%d,%d,%d"

a,b,c);

(2)P53页2输入一个不超过5位的整数,求解该数是几位数,计算机该数各位数字的和;

将该数逆序输出。

如用户输入的数为178,则输出871

intnum,ten_thousand,thousand,hundred,ten,indiv,place;

printf("

请输入一个整数(0-99999):

"

);

scanf("

%d"

&

num);

if(num>

9999)

place=5;

elseif(num>

999)

place=4;

99)

place=3;

9)

place=2;

elseplace=1;

这个数是%d位数!

\n"

place);

ten_thousand=num/10000;

//ten_thousand代表万位,以下分别代表千位、百位、十位和个位

thousand=(num-ten_thousand*10000)/1000;

hundred=(num-ten_thousand*10000-thousand*1000)/100;

ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;

indiv=(num-ten_thousand*10000-thousand*1000-hundred*100)%10;

switch(place)

{

case5:

这个数的正序是:

%d%d%d%d%d\n"

ten_thousand,thousand,hundred,ten,indiv);

printf("

这个数的逆序是:

indiv,ten,hundred,thousand,ten_thousand);

break;

case4:

%d%d%d%d\n"

thousand,hundred,ten,indiv);

indiv,ten,hundred,thousand);

case3:

%d%d%d\n"

hundred,ten,indiv);

indiv,ten,hundred);

case2:

%d%d\n"

ten,indiv);

indiv,ten);

case1:

%d\n"

indiv);

}

(3)P53页3编程判断输入的整数的正负性和奇偶性并进行输出。

intn;

请输入一个整数:

n);

if(n>

=0)

if(n%2==0)

printf("

这是个正偶数\n"

else

这是个正奇数\n"

else

这是个负偶数\n"

这是个负奇数\n"

(4)P53页4输入三角形三条边长a,b,c,判断它们能否构成三角形,若能构成三角形,指出是何种三角形。

详细说明请看教材。

//是否构成三角形

inta,b,c;

请输入三角形三条边长:

%d%d%d"

if(a+b<

=c||a+c<

=b||b+c<

=a)

不能构成三角形!

return;

if(a==b&

b==c)

这个三角形是等边三角形"

elseif(a==b||b==c||a==c)

这个三角形是等腰三角形"

else

这个三角形是普通三角形"

(1)P83页4编写程序,输出200以内所有能被7整除的数。

inti,count=0;

200之内能被7整除的数是:

for(i=7;

i<

=200;

i++)

if(i%7==0)

%5d"

i);

count++;

if(count%5==0)

(2)P84页8.

//1元换1分、2分和5分

intx,y,z,count1=0;

1分\t2分\t5分\n"

for(x=1;

=100;

x++)

for(y=1;

y<

=50;

y++)

for(z=1;

z<

=20;

z++)

{

if(x+2*y+5*z==100)

{

printf("

%d\t%d\t%d\n"

x,y,z);

count1++;

if(count1%50==0)

{

printf("

请按回车键继续……\n"

getchar();

}

}

(1)P124页1编写函数判断一个整数是否是素数。

参考73页例题

math.h>

voidsushu(intnum);

intnum;

sushu(num);

voidsushu(intnum)

inti,n;

n=sqrt(num);

for(i=2;

=n;

if(num%i==0)

break;

if(i>

n)

%d是素数"

num);

%d不是素数"

(2)P124页3编写函数返回一个整数的位数,并用主函数调用该函数。

注意函数应首先测试给现的整数是否是负数,如果是负数,应对它的相反数求位数。

第一种:

intweishu(intn);

intn,place;

请输入一个数:

place=weishu(n);

这是%d位数\n"

intweishu(intn)

{

if(n<

0)

n=-n;

return5;

elseif(n>

return4;

elseif(n>

return3;

elseif(n>

return2;

else

return1;

第二种解法:

intcount=1;

do

n=n/10;

count++;

}while(n);

returncount;

(3)P124页8,给出年、月、日,计算该日是该年中的第几天。

提示:

关键在于每个月的天数,编个函数实现计算每个月的天数,可用switch语句,另外如果是二月,还要考虑是否是闰年,再编个函数实现闰年的判断

intmonthdays(intyear,intmonth);

inti,year,month,day,days=0;

请输入年月日:

year,&

month,&

day);

for(i=1;

month;

days=days+monthdays(year,i);

days=days+day;

这是这一年的第%d天!

days);

intmonthdays(intyear,intmonth)

switch(month)

case2:

if((year%4==0&

year%100!

=0)||(year%400==0))

return29;

elsereturn28;

case4:

case6:

case9:

case11:

return30;

default:

return31;

1、P144页1由于各裁判打分时可能存在某些主观因素,因此在计算平均分时通常去掉一个最高分和一个最低分。

写一个程序,读入7个裁判所打的分数,去掉一个最高分和一个最低分,计算剩余5个裁判的平均分。

#defineNJudges7

intmain(void)

floatscores[NJudges];

//数组用来存分数

floattotal=0.0,max=0.0,min=10;

floataverage=0.0;

inti;

Enterascoreforeachjudge:

for(i=0;

NJudges;

Scoreforjudge#%d:

i+1);

scanf("

%f"

scores[i]);

total+=scores[i];

if(scores[i]>

max)

max=scores[i];

if(scores[i]<

min)

min=scores[i];

average=(total-max-min)/(NJudges-2);

Theaveragescoreis%.2f\n"

average);

return0;

2、P144页2写一个程序,用选择法对20个整数排序。

#defineN20

inti,a[N],j,k,t;

输入数组元素:

N;

a[i]);

数组是:

%3d"

a[i]);

=N-2;

k=i;

for(j=i+1;

j<

=N-1;

j++)

if(a[j]<

a[k])

k=j;

t=a[k];

a[k]=a[i];

a[i]=t;

排序后的数组是:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2