【c++编程从零学】第八讲练习题题解

1.

#include <iostream>
using namespace std;
int main(){
    int n,i=1,sum=0;
    cin>>n;
    while(i<=n){
        sum+=i;
        i++;
    }
    cout<<sum;
}

2.
循环版:

#include <iostream>
using namespace std;
int main(){
    cout<<"一   二   三   四   五   六   日"<<endl;
    cout<<"          ";
    int n=1,h=2;
    while(n<=30){
        if(n<=9) cout<<n<<"    ";
        if(n>=10) cout<<n<<"   ";
        h++;
        if(h%7==0) cout<<endl;
        n++;
    }
    return 0;
}

还有直接打印。


以上是【c++编程从零学】第八讲练习题题解,咱们下周再见!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容