- #include <stdio.h>
- void zhengsanjiao(int n){
- for (int i = 0; i<n; i++) {
- for (int j = 0; j <= n-i+1; j++) {
- printf(" ");
- }
- for (int j = 0; j <= 2*i-2; j++) {
- printf("*");
- }
- printf("\n");
- }
- }
- void daosanjiao(int n){
- for (int i= 0; i < n; i++) {
- for (int j = 0; j <= i+1; j++) {
- printf(" ");
- }
- for (int j = 2*i+1; j <= 2*n-1; j++) {
- printf("*");
- }
- printf("\n");
- }
- }
- int main(int argc, const char * argv[]) {
- int len;
- printf("请输入一个整数:\n");
- scanf("%d",&len);
- zhengsanjiao(len);
- daosanjiao(len);
- return 0;
- }
复制代码
|
|