1.终端输入行数,打印金字塔图案
//代码
#include<stdio.h>int main(int argc, const char *argv[])
{int n;printf("请输入行数:\n");scanf("%d", &n);int i,j;i = 1;while(i<=n){j=0;while(j<n-i){putchar(' '); //打印前面的空格j++;}j=0;while(j<2*i-1){putchar('*'); //打印*j++;}j=0;while(j<n-i){putchar(' '); //打印后面的空格j++;}i++;putchar('\n');}return 0;
}//运行结果
zzy@zzy-vm:~/c_program/day4$ ./test11
请输入行数:
5* *** ***** *******
*********
zzy@zzy-vm:~/c_program/day4$ ./test11
请输入行数:
10* *** ***** ******* ********* *********** ************* *************** *****************
*******************
2.打印字母图形
//代码
#include<stdio.h>int main(int argc, const char *argv[])
{char a;printf("请输入字母:\n"); //a-z:97-122,A-Z:65-90scanf("%c", &a);int n; //行数if(a>='a'&&a<='z')n = a - 96;else if(a>='A'&&a<='Z')n = a - 64;int i,j;i = 0;while(i<n){j = 0;while(j<i){putchar('_');j++;}j = 0;while(j<i+1){putchar(a-j);j++;}putchar('\n');i++;}return 0;
}//运行结果
zzy@zzy-vm:~/c_program/day4$ ./test12
请输入字母:
f
f
_fe
__fed
___fedc
____fedcb
_____fedcba
zzy@zzy-vm:~/c_program/day4$ ./test12
请输入字母:
H
H
_HG
__HGF
___HGFE
____HGFED
_____HGFEDC
______HGFEDCB
_______HGFEDCBA