课程主页在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菜鸟起飞铺跑道,和学生一起享受快乐和激情的大学 ===== |