#include<stdio.h> #include<stdlib.h> #include<iostream> #include<math.h> using namespace std; int main() { int n=0; cin>>n; int i=0; for(int k=1-n;k<=n-1;k++) { //-4 -3 -2 -1 0 // 1 2 3 4 5 //i=n-abs(k) i=n-abs(k); //先求行数 //先输出空格,再输出字母 //空格为4 3 2 1 0 1 2 3 4 for(int j=1;j<=abs(k);j++) printf(" "); for(int j=1;j<=2*i-1;j++) printf("*"); printf("\n"); } //system("pause"); } |
Double click to view unformatted code.