2014秋C++第9周项目5参考-循环填充题

课程主页在http://blog.csdn.net/sxhelijian/article/details/39152703。课程资源在云学堂“贺老师课堂”同步展示,使用的帐号请到课程主页中查看。

 

【项目5:程序填充题】在程序中横线上填上恰当的成分,使完成题目要求的功能:

1.输出1000以内能被3整除且个位数为6的所有整数。

#include <iostream>
using namespace std;
int main()
{
    int  i, j;
    for (i=0;_________; i++)         // (1)
    {  
        j=i*10+6;
        if (j%3==0)
             ____________;    // (2)
    }
    cout<<endl;
    return 0;     
}
参考答案:
#include <iostream>
using namespace std;
int main()
{
    int  i, j;
    for (i=0;i<100; i++)         // (1)
    {
        j=i*10+6;
        if (j%3==0)
             cout<<j<<" ";    // (2)
    }
    cout<<endl;
    return 0;
}


2 .输入 10 个整数,找出最大数。

#include <iostream>
using namespace std;
int main()
{
  int  k,x,max;
  cin>>x;
  max=______;                 // (1)
  for(k=2;  k<=___ ; k++)       //  (2)
  {
     cin>>x;
     if (_______)  max=x;      //  (3)
  }
  cout<<"Max="<<max<<endl;
  return 0;     
}

参考解答:
#include <iostream>
using namespace std;
int main()
{
  int  k,x,max;
  cin>>x;
  max=x;                 // (1)
  for(k=2;  k<=10 ; k++)       //  (2)
  {
     cin>>x;
     if (max<x)  max=x;      //  (3)或x>max
  }
  cout<<"Max="<<max<<endl;
  return 0;
}


3.从键盘输入20个整数,输出它们的和。

#include <iostream>
using namespace std;
int main()
{
   int a,sum=0;
   for (int i=1;i<=20;________)     // (1)
   {
      cin>>a;   
      sum=______;                //  (2)
   }
   cout<<"sum="<<sum<<endl;
   return 0;      
}

参考解答:

#include <iostream>
using namespace std;
int main()
{
   int a,sum=0;
   for (int i=1;i<=20;i++)     // (1)
   {
      cin>>a;   
      sum=sum+a;                //  (2)
   }
   cout<<"sum="<<sum<<endl;
   return 0;      
}




=================== 迂者 贺利坚 CSDN博客专栏=================
|== IT学子成长指导专栏 专栏文章的分类目录(不定期更新) ==|
|== C++ 课堂在线专栏  贺利坚课程教学链接(分课程年级) ==|
|== 我写的书——《逆袭大学——传给IT学子的正能量》    ==|
===== 为IT菜鸟起飞铺跑道,和学生一起享受快乐和激情的大学 =====

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

迂者-贺利坚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值