网站大量收购独家精品文档,联系QQ:2885784924

C语言编程大题.doc

  1. 1、本文档共11页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
1、随机产生10个数存入一维数组a中,求这10数中的最大数并输出。 #includestdio.h #includestdlib.h main() {int a[10],i,max; for(i=0;i10;i++) {a[i]=rand()%50; max=a[0]; if(maxa[i]) max=a[i];} printf(%d\n,max); } 41 Press any key to continue 2,从键盘上输入a与n的值,计算sum=a+aa+aaa+aaaa+…(共n项)的和。例a=2,n=4,则sum=2+22+222+2222. #includestdio.h #includeiostream.h #includestring.h main() { int a,n,i,sum=0,sum1; printf(input two number:); scanf(%d,a); scanf(%d,n); sum1=a; for(i=2;i=n;i++) { sum1=sum1*10+a; sum=sum+sum1; } printf(the result is %d\n,sum);} input two number:2 4 the result is 2466 Press any key to continue 3,编写程序,输出100~500之间的所有素数,每行输出5个。 #include stdio.h void main() { int i,j,k,min=100,max=500,temp=1; for(i=min;i=max;i++) { for(j=2;j=i/2+1;j++) { if(i%j==0) break; } if (j i/2+1){ temp++; printf(%5d,i); } if(temp==6) { temp=1; printf(\n); } } } 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 Press any key to continue 4,有一头母牛,它每年年初生一头小母牛,每头小母牛从第四个年头起,每年年初也生一头小母牛,编写程序,求第20年时,共有多少头牛。 #includestdio.h int main() { int n,s[100],i,sum; while(scanf(%d,n)!=EOF) { if(n==0)break; s[0]=s[1]=s[2]=0; s[3]=1; for(i=1;in;i++) { s[3]=s[3]+s[2]; s[2]=s[1]; s[1]=s[0]; s[0]=s[3]; } sum=s[0]+s[1]+s[2]+s[3]; printf(%d\n,sum); } return 0; } 20 1873 5,编写程序,输出下列三角形: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 #includestdio.h main() { int i,j,k; for(i=0;i4;i++) { for(k=1;k=i;k++) printf( ); for(j=0;j7-i*2;j++) printf(1); printf(\n); } } 1111111 11111 111 1 Press any key to continue 6, 编写程序,输出下列三角形: 1 1 1 1 1 1 1 1 1 1 1

文档评论(0)

精品报告 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档