C language basics, C Language

Source: Internet
Author: User

C language basics, C Language

For example:

At first glance, I thought of printing numbers first and then combining them to form a combination of numbers.

First of all, I wonder if I can use a for loop for control. After all, a number on a computer is composed of plum blossom and space, like this code.

void print1() {    int i, j;    for (i = 0;i < 6; i++)        printf("       *\n");    printf("\n");}void print2() {    int i, j;    for (i = 0; i < 6; i++)        printf("*");    for (i = 0; i < 4; i++) {        printf("\n");        for (j = 0; j < 4 - i; j++)            printf(" ");        printf("*");    }printf("\n");    for (i = 0; i < 6; i++)        printf("*");    printf("\n");}

You can also input and print numbers one by one. However, the combined output of multiple numbers cannot be completed. It can only look at the array, a number is a two-dimensional array, multiple numbers form a three-dimensional array. So the code can be written like this!

#include<stdio.h>#include<string.h>int main(){    char b[100], a[10][5][6] = { ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', '*', ' ',        ' ', ' ', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ',        ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', '*', ' ', ' ', ' ', '*', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ',        ' ', '*', '*', '*', '*', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ',        ' ', ' ', '*', '*', '*', ' ',  ' ', '*', ' ', ' ', ' ', ' ',  ' ', '*', ' ', '*', ' ', ' ',  ' ', '*', '*', '*', '*', '*',  ' ', ' ', ' ', '*', ' ', ' ',         ' ', ' ', ' ', '*', ' ', ' ',  ' ','*', '*', '*', ' ', ' ',  ' ', '*', ' ', ' ', ' ', ' ',  ' ', '*', '*', '*', ' ', ' ',  ' ', ' ', ' ', ' ', '*', ' ',         ' ', '*', '*', '*', ' ', ' ',  ' ', ' ', ' *', '*', '*', ' ',  ' ', '*', ' ', ' ', ' ', ' ',  ' ', '*', '*', '*', '*', ' ',  ' ', '*', ' ', ' ', '*', ' ',         ' ', '*', '*', '*', '*', ' ',  ' ', '*', '*', '*', '*', ' ',  ' ', ' ', ' ', ' ', '*', ' ',  ' ', ' ', ' ', ' ', '*', ' ',  ' ', ' ', ' ', ' ', '*', ' ',         ' ', ' ', ' ', ' ', '*', ' ',  ' ', '*', '*', '*', ' ', ' ',  '*', ' ', ' ', ' ', '*', ' ',  ' ', ' ', '*', ' ', ' ', ' ',  '*', ' ', ' ', ' ', '*', ' ',         ' ', '*', '*', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', '*', ' ', ' ', ' ', '*', ' ', ' ', ' ', '*', '*', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ', ' ', ' ', ' ', ' ', '*', ' ' };    int i, j, k, n = 0;    gets_s(b);    n = strlen(b);    for (j = 0; j < 5; j++)    {        for (k = 0; k < n; k++)        {            if (b[k] == '0')            for (i = 0; i < 6; i++)                printf("%c", a[0][j][i]);            if (b[k] == '1')            for (i = 0; i < 6; i++)                printf("%c", a[1][j][i]);            if (b[k] == '2')            for (i = 0; i < 6; i++)                printf("%c", a[2][j][i]);            if (b[k] == '3')            for (i = 0; i < 6; i++)                printf("%c", a[3][j][i]);            if (b[k] == '4')            for (i = 0; i < 6; i++)                printf("%c", a[4][j][i]);            if (b[k] == '5')            for (i = 0; i < 6; i++)                printf("%c", a[5][j][i]);            if (b[k] == '6')            for (i = 0; i < 6; i++)                printf("%c", a[6][j][i]);            if (b[k] == '7')            for (i = 0; i < 6; i++)                printf("%c", a[7][j][i]);            if (b[k] == '8')            for (i = 0; i < 6; i++)                printf("%c", a[8][j][i]);            if (b[k] == '9')            for (i = 0; i < 6; i++)                printf("%c", a[9][j][i]);        }        printf("\n");    }    return 0;    }

The problem is solved !~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.