哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx

上传人:b****2 文档编号:4559192 上传时间:2023-05-03 格式:DOCX 页数:36 大小:20.16KB
下载 相关 举报
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第1页
第1页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第2页
第2页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第3页
第3页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第4页
第4页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第5页
第5页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第6页
第6页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第7页
第7页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第8页
第8页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第9页
第9页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第10页
第10页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第11页
第11页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第12页
第12页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第13页
第13页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第14页
第14页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第15页
第15页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第16页
第16页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第17页
第17页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第18页
第18页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第19页
第19页 / 共36页
哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx_第20页
第20页 / 共36页
亲,该文档总共36页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx

《哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx(36页珍藏版)》请在冰点文库上搜索。

哈工大MOOC课件编程题参考答案79周Word格式文档下载.docx

a<

9;

a++)

for(b=1;

b<

b++)

for(c=1;

c<

c++)

n=122*a+212*b+221*c;

if(m==n)

Thenumberis%d\n"

100*a+10*b+c);

return1;

3.寻找中位数v1.0

stdlib.h>

intmid(inta,intb,intc);

inta,b,c;

%d%d%d"

a,&

b,&

c);

Theresultis%d\n"

mid(a,b,c));

intmid(inta,intb,intc)

inttmp1=a,tmp2,tmp3,tmp4;

if(tmp1>

b)

tmp1=b;

tmp2=a;

tmp3=c;

c)

tmp1=c;

tmp3=b;

if(tmp2>

tmp3)

tmp4=tmp3;

tmp3=tmp2;

tmp2=tmp4;

tmp2=b;

tmp3=a;

returntmp2;

4.还原算术表达式

intx,y,z,n,flag=0;

Inputn(n<

1000):

for(x=0;

x<

=5;

x++)

for(y=0;

y<

y++)

for(z=0;

z<

=9;

z++)

if(100*x+10*y+z+z+10*z+100*y==n)

X=%d,Y=%d,Z=%d\n"

x,y,z);

flag=1;

break;

if(flag==0)printf("

Invalid\n"

第七周_练兵区

1.谐均值计算

#include<

doubleCalculate(double,double);

doublea,b;

Inputtwodoubles:

%lf%lf"

b);

1/((1/x+1/y)/2)=%0.3f\n"

Calculate(a,b));

doubleCalculate(doublex,doubley)

return1/((1/x+1/y)/2);

2.输出指定行列数的字符

voidChline(charch,intcolumn,introw);

intx,y;

charch;

inputachar:

%c"

ch);

inputcolumnandrow:

%d%d"

x,&

y);

Chline(ch,x,y);

voidChline(charch,intcolumn,introw)

for(y=0;

y<

row;

y++)

for(x=0;

x<

column;

x++)

ch);

第八周_在线测试

1.计算礼炮声响次数

intt,n=0;

for(t=0;

t<

=140;

t++)

if(t%5==0&

&

t<

=21*5)

n++;

continue;

if(t%6==0&

=21*6)

if(t%7==0&

=21*7)

n=%d"

n);

2.兔子生崽问题

#defineN12

intFibonacci(intf[],intn);

intf[N],i,num,sum;

=12):

num);

sum=Fibonacci(f,num);

\nTotal=%d\n"

sum);

/*函数功能:

计算并打印Fibonacci数列的前n项*/

intFibonacci(intf[],intn)

inti,sum=0;

f[0]=1;

f[1]=2;

for(i=2;

i<

n;

i++)

f[i]=f[i-1]+f[i-2];

for(i=0;

%4d"

f[i]);

i<

i++)

sum=sum+f[i];

returnsum;

3.抓交通肇事犯

inta,b,c,d,i,j;

for(i=31;

100;

j=i*i;

a=j/1000;

d=j%10;

b=j%1000/100;

c=j%100/10;

if(a==b&

c==d&

a!

=c)

k=%d,m=%d\n"

j,i);

4.检验并打印幻方矩阵

#define

N5

inti,j;

intx[N][N];

=4;

for(j=0;

j<

j++)

x[i][j]);

introwSum[N],colSum[N],diagSum1,diagSum2;

intflag=1;

for(i=0;

i<

N;

rowSum[i]=0;

for(j=0;

j<

j++)

rowSum[i]=rowSum[i]+x[i][j];

colSum[j]=0;

colSum[j]=colSum[j]+x[i][j];

diagSum1=0;

diagSum1=diagSum1+x[j][j];

diagSum2=0;

diagSum2=diagSum2+x[j][N-1-j];

if(diagSum1!

=diagSum2)

flag=0;

if((rowSum[i]!

=diagSum1)||(colSum[i]!

=diagSum1))

if(flag)

Itisamagicsquare!

x[i][j]);

Itisnotamagicsquare!

第八周_练兵区

1.三天打渔两天晒网

inty,m,d;

intsum=0;

%4d-%2d-%2d"

y,&

m,&

d);

if(y<

1990)

Invalidinput."

if((y%100!

=0&

y%4==0)||(y%400==0))

switch(m)

case1:

case3:

case5:

case7:

case8:

case10:

case12:

if(d>

31||d<

1)

Invalidinput"

case2:

29||d<

case4:

case6:

case9:

case11:

30||d<

default:

28||d<

inti;

if(y>

for(i=1990;

y;

if((i%100!

i%4==0)||(i%400==0))

sum=sum+366;

sum=sum+365;

inti1;

if(m>

for(i1=1;

i1<

m;

i1++)

switch(i1)

sum=sum+31;

sum=sum+29;

sum=sum+30;

sum=sum+28;

sum=sum+d;

sum=sum%5;

if(sum==0||sum==4)

Heishavingarest"

Heisworking"

2.统计用户输入

intspace=0,newline=0,others=0;

chara;

Pleaseinputastringendby#:

while((a=getchar())!

='

#'

if(a=='

'

)space++;

elseif(a=='

\n'

)newline++;

elseothers++;

space:

%d,newline:

%d,others:

%d\n"

space,newline,others);

return(0);

3.统计正整数中指定数字的个数

intCountDigit(intnumber,intdigit)

intcount=0;

do

if(digit==number%10)count++;

number=number/10;

}while(number>

9);

returncount;

intm,n;

printf("

Inputm,n:

scanf("

%d,%d"

%d\n"

CountDigit(m,n));

4.玫瑰花数

inti,a,n,s,m;

for(a=1000;

a<

=9999;

a++)//遍历所有的4位数

n=a;

for(s=0,i=1;

m=n%10;

n=n/10;

//求出当前n的最低位

//将n缩小10倍,去掉最低位

s=s+m*m*m*m;

//计算4位数字的4次方之和

if(a==s)

//满足4位数等于其4位数字的4次方之和的即为玫瑰花数

a);

5.四位反序数

源码1:

inti,j,k,m;

for(i=1;

i++)//千位从1变化到9

j<

j++)//百位从0变化到9

for(k=0;

k<

k++)//十位从0变化到9

for(m=1;

m<

m++)//个位从1变化到9

if(9*(i*1000+j*100+k*10+m)==m*1000+k*100+j*10+i)

i*1000+j*100+k*10+m);

源码2:

for(i=1001;

1111;

i++)//遍历所有的9倍之后仍为4位数的数

if(i%10*1000+i/10%10*100+i/100%10*10+i/1000==i*9)

i);

6.8除不尽的自然数

inta,find=0;

for(a=0;

!

find;

if(((a*8+7)*8+1)*8+1==(34*a+15)*17+4)

(34*a+15)*17+4);

find=1;

inti,find=0;

for(i=1992;

if(i%8==1)

if((i/8)%8==1)

if((i/8/8)%8==7)

if(i%17==4)

if((i/17)%17==15)

if((i/17/17)==2*(i/8/8/8))

i);

第九周_在线测试

1.ISBN识别码判断

charisbn[13];

inti,k=0,last,p;

gets(isbn);

for(i=0,p=0;

11;

i++)

if(isbn[i]=='

-'

)continue;

p++;

k+=(isbn[i]-48)*p;

last=k%11;

if(last==10)

last='

X'

;

last+=48;

if(last==isbn[12])

Right"

isbn[12]=last;

%s"

isbn);

2.摘苹果

inta[10];

intheight,get=0;

for(i=0;

10;

a[i]);

height);

if((height+30)>

=a[i])

get++;

get);

3.求最大素数

math.h>

intsum_prime(inta[],intn);

intprime(intn);

inti,a[10],sum;

intnum;

=500):

sum=sum_prime(a,num);

%6d"

a[i]);

\nsum=%d\n"

intsum_prime(inta[],intn)

inti,j=n,sum=0;

if(prime(j))

sum=sum+j;

a[i]=j;

i++;

j--;

intprime(intn)

inti,k;

k=(int)sqrt((double)n);

for(i=2;

=k;

if(n%i==0)

if(i>

=k+1)

4.字符串逆序

string.h>

#defineN80

voidInverse(charstr[]);

chara[N];

Inputastring:

gets(a);

Inverse(a);

Inversedresults:

puts(a);

voidInverse(charstr[]

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

当前位置:首页 > 解决方案 > 学习计划

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

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