2170 - 打印星形三角
根据输入的N,输出N行型号图形,如N=5时。
*
***
Input
正整数N
Output
N行星号图形
Examples
Input
5
Output
* ** *** **** *****
Solution C
#include<stdio.h> int main(){ int N,i,j; scanf("%d",&N); for(i=1;i<=N;i++){ for(j=1;j<=i;j++){ printf("*"); } printf("\n"); } return 0; }
Solution C++
#include <iostream> using namespace std; int main(){ int a; int pos=1; cin>>a; while(pos<=a){ for(int i=1;i<=pos;i++) cout<<'*'; cout<<endl; pos++; } return 0; }