- 终端输入行数,打印金字塔
ubuntu@ubuntu:~$ cat day4work1.c #include<stdio.h> int main(int argc,const char *argv[]) { int line; int i=1 ,j,k; scanf("%d",&line); while(i<=line) //外层循环,控制循环行数 { j=1; while(j<=line-i) { printf(" "); j++; } k=1; while(k<=i*2-1) { printf("*"); k++; } putchar(10); i++; } return 0; } ubuntu@ubuntu:~$ gcc day4work1.c ubuntu@ubuntu:~$ ./a.out 5 * *** ***** ******* *********
2.打印字母图案
ubuntu@ubuntu:~$ cat day4work3.c #include<stdio.h> int main(int argc,const char *argv[]) { int line = 6; char c = 'F'; int i=1,j; while(i<=line) { c = 'F'; j=1; while(j<=i-1) { printf("-"); j++; } j = 1; while(j<=i) { printf("%c",c); c--; j++; } putchar(10); i++; } return 0; } ubuntu@ubuntu:~$ gcc day4work3.c ubuntu@ubuntu:~$ ./a.out F -FE --FED ---FEDC ----FEDCB -----FEDCBA
3.
day4 work
于 2023-04-05 08:58:56 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)