C 语言教程 在线

1675c-exercise-example9

参考方案:

#include<stdio.h>

int main()
{
    int i,j;
    for(i=0;i<8;i++){
        if(i % 2){
            printf("%c%c  %c%c  %c%c  %c%c  \n", 219, 219, 219, 219, 219, 219, 219, 219);
        }else{
            printf("  %c%c  %c%c  %c%c  %c%c\n", 219, 219, 219, 219, 219, 219, 219, 219);
        }
    }
    return 0;
}

1674c-exercise-example8

参考方法:

#include<stdio.h>
int main(void)
{
    int i, j;
    for(i = 1;i < 10; i++)
    {
        for(j = 1;j <= i; j++)
        {
            printf("%d*%d=%d  ",i,j,i*j);
        }
        printf("\n");
    }
    return 0;
}

1673c-exercise-example8

使用制表符 \t

#include<stdio.h>

int main()
{
    char i,j;
    for(i=1;i<10;i++)
    {
        for(j=1;j<i+1;j++)
        {
           printf("%d*%d=%d\t",i,j,i*j);
        }
       printf("\n");
    } 
    return 0;
}

1672c-exercise-example8

使用 while:

#include <stdio.h>

int main()
{
    int a,b,c,d;
    a = 1;
    b = 1;
    while (a <= 9)
    {
        for (c=1;c<=b;c++)
        {
            d = b * c;
            printf("%d*%d=%d ",b,c,d);
        }
        a++;
        b++;
        printf("\n");
    }
    return 0;
}

1671c-exercise-example7

参考方法:

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int main(void)
{
    int i,j;
    SetConsoleOutputCP(437);
    char a=176,b=219;
    for(i=0;i<5;i++)
    {
        for(j=0;j<5;j++)
        {
            if(i==j||(i+j+1)==5)
                printf("%c",b);
            else
                printf("%c%c",a,a);
        }
        printf("\n");
    }
}