#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { /*Description:从键盘输入一个整数n(1≤n≤9),打印出指定的数字图形*/ int num; int i,j; //printf("Please input the number: "); scanf("%d",&num); //printf("The figure is:\n"); for(i=1; i<=num; i++){ for(j=1;j<=num-i;j++){ printf(" "); } for(j=1;j<=i;j++){ printf("*"); } for(j=i-1;j>0;j--){ printf("*"); } printf("\n"); } for(i=num-1;i>0;i--){ for(j=1;j<=num-i;j++){ printf(" "); } for(j=1;j<=i;j++){ printf("*"); } for(j=i-1;j>0;j--){ printf("*"); } if(i!=1) printf("\n"); } return 0; } |
Double click to view unformatted code.