标签:
#include <stdio.h> #include <stdlib.h> void printRhombus(int number); //打印边长为number的正菱形 void printUpTri(int number,int left); //打印边长为number的向上正三角形,左边空left列 void printDownTri(int number,int left); //打印边长为number的向下正三角形,左边空left列 void printRow(int number, int row, int left); int main(){ int number; while (fflush(stdin), scanf("%d", &number) != EOF) printRhombus(number); system("pause"); return 0; } void printRhombus(int number){ printUpTri(number,0); printDownTri(number - 1,1); } void printUpTri(int number,int left){ for (int i = 1; i <= number; ++i) //i为当前行 printRow(number,i,left); } void printDownTri(int number,int left){ for (int i = number; i > 0; --i) //i为当前行*数 printRow(number,i,left); } void printRow(int number, int row, int left){ for (int j = 0; j < left; ++j) //打印空列 printf(" "); for (int j = 0; j < number - row; ++j) //打印左方空白 printf(" "); for (int j = 0; j < row; ++j) //打印三角形的一行 printf("* "); printf("\n"); }
标签:
原文地址:http://www.cnblogs.com/mutaohengheng/p/5108035.html