P5721 【深基4.例6】数字直角三角形
思路
首先可以知道要输出的是一个第一行为 个数,第二行输出 个数,第三行输出 个数,最后一行输出 个数。一共有 行,所以我们可以用两层循环,第一层是遍历第几行的,因为第一行有 个数,所以从 开始遍历。第二层则是每行有几个数。还要判断前导 哦。
Code
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int c=1;
for (int i=n;i>=1;i--){
for (int j=1;j<=i;j++){
if (c<10){
cout<<"0"<<c;
}
else{
cout<<c;
}
c++;
}
cout<<endl;
}
return 0;
}