给大家推荐一门大数据Spark入门课程https://www.bilibili.com/video/BV1oi4y147iD/,希望大家喜欢。
习题6
用 * 号输出字母C的图案。
实现思路: 单行打印即可。
代码如下:
1#include <stdio.h> 2 3int main (void) 4{ 5 printf("****\n"); 6 printf("*\n"); 7 printf("*\n"); 8 printf("****\n"); 9 10 return 0; 11}
打印:
1**** 2* 3* 4**** 5
习题7
输出图形如下:
实现思路: 使用符合输出形状的字符逐行输出。
代码如下:
1#include<stdio.h> 2 3int main() 4{ 5 char a=2,b=4; 6 printf("%c%c%c%c%c\n",b,a,a,a,b); 7 printf("%c%c%c%c%c\n",a,b,a,b,a); 8 printf("%c%c%c%c%c\n",a,a,b,a,a); 9 printf("%c%c%c%c%c\n",a,b,a,b,a); 10 printf("%c%c%c%c%c\n",b,a,a,a,b); 11 12 return 0; 13}
打印:
1 2 3 4 5 6
习题8
输出9×9乘法表。
实现思路: 嵌套循环,分别控制行和列。
代码如下:
1#include<stdio.h> 2 3int main() 4{ 5 int i, j; 6 printf(" "); 7 for(j = 1; j < 10; j++){ 8 printf("%8d", j); 9 } 10 printf("\n\n"); 11 for(i = 1; i < 10; i++){ 12 printf("%-4d", i); 13 for(j = 1; j <= i; j++){ 14 printf(" %dx%d=%2d", j, i, i * j); 15 } 16 printf("\n"); 17 } 18 19 return 0; 20}
打印:
1 1 2 3 4 5 6 7 8 9 2 31 1x1= 1 42 1x2= 2 2x2= 4 53 1x3= 3 2x3= 6 3x3= 9 64 1x4= 4 2x4= 8 3x4=12 4x4=16 75 1x5= 5 2x5=10 3x5=15 4x5=20 5x5=25 86 1x6= 6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 97 1x7= 7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 108 1x8= 8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 119 1x9= 9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 12
习题9
输出国际象棋棋盘。
实现思路: 嵌套循环,分别控制列和行。
代码如下:
1#include<stdio.h> 2 3int main() 4{ 5 int i, j; 6 for(i = 0; i < 8; i++){ 7 for(j = 0; j < 8; j++){ 8 if((i + j) % 2 == 0){ 9 printf("%c", 4); 10 } 11 else{ 12 printf(" "); 13 } 14 } 15 printf("\n"); 16 } 17 18 return 0; 19}
打印:
1 2 3 4 5 6 7 8 9
习题10
打印楼梯,同时在楼梯上方打印两个笑脸。
实现思路: 嵌套循环,分别控制行和列。
代码如下:
1#include<stdio.h> 2 3int main() 4{ 5 int i, j; 6 printf("\n^_^ ^_^\n\n"); 7 for(i = 0; i < 20; i++){ 8 for(j = 0; j <= i; j++){ 9 printf(" "); 10 } 11 printf("%c\n", 4); 12 } 13 14 return 0; 15}
打印如下:
1 2^_^ ^_^ 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
本文原文首发来自博客专栏C语言实战,由本人转发至https://www.helloworld.net/p/BwwI4dcJmi0o,其他平台均属侵权,可点击https://blog.csdn.net/CUFEECR/article/details/106400164查看原文,也可点击https://blog.csdn.net/CUFEECR浏览更多优质原创内容。

