1.输出"Hello World!"
代码:
#include<iostream>
using namespace std;
int main(){
cout<<"Hello World!"<< endl;
return 0;
}
结果:

2.输出金字塔
分析:第一行输出3个空格+1个*,第二行输出2个空格+1个*,第三行......

代码:
#include<iostream>
using namespace std;
int main(){
cout<<" "<<"*"<<endl;
cout<<" "<<"***"<<endl;
cout<<" "<<"*****"<<endl;
cout<<""<<"*******"<<endl;
return 0;
}
结果:

3.求一个三位数各个位上的数字之和
代码:
#include<iostream>
using namespace std;
int main(){
int a;
cin>>a;
cout<<a/100+a%10+a%100/10;
return 0;
}
结果:

这个博客包含一系列C++基础编程练习,如输出"Hello World!",输出金字塔,求三位数数字之和,整数的平方和,变量交换,数字乘积与三次方和,时间转化等,适合初学者提升编程技能。
最低0.47元/天 解锁文章
6513

被折叠的 条评论
为什么被折叠?



