OpenJudge - NOI - 1.1編程基礎之輸入輸出(C語言 所有題解)

01:Hello, World!

#include <stdio.h>

int main(void)
{
    printf("Hello, World!");
    return 0;
}

02:輸出第二個整數

#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%d", b);
    return 0;
}

03:對齊輸出

#include <stdio.h>

int main(void)
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%8d %8d %8d", a, b, c);/* 注意輸出的格式 */
    return 0;
}

04:輸出保留3位小數的浮點數

#include <stdio.h>

int main(void)
{
    float num;
    scanf("%f", &num);
    printf("%.3f", num);/* 注意輸出的格式 */
    return 0;
}

05:輸出保留12位小數的浮點數

#include <stdio.h>

int main(void)
{
    double num;
    scanf("%lf", &num);
    printf("%.12f", num);/* 注意輸出的格式 */
    return 0;
}

06:空格分隔輸出

#include<stdio.h>

int main(void)
{
    char ch;
    int a;
    float b;
    double c;
    scanf("%c%d%f%lf", &ch, &a, &b, &c);
    printf("%c %d %.6f %.6lf", ch, a, b, c);
    return 0;
}

07:輸出浮點數

#include<stdio.h>

int main(void)
{
    double num;
    scanf("%lf", &num);
    printf("%f\n%.5f\n%e\n%g", num, num, num, num);/* \n是回車換行符,將當前位置移到下一行開頭 */
    return 0;
}

08:字符三角形

#include<stdio.h>

int main(void)
{
    char ch;
    scanf("%c", &ch);
    /* 輸出空格來代替空白 */
    printf("  %c  \n", ch);
    printf(" %c%c%c \n", ch, ch, ch);
    printf("%c%c%c%c%c\n", ch, ch, ch, ch, ch);
    return 0;
}

09:字符菱形

#include<stdio.h>

int main(void)
{
    char ch;
    scanf("%c", &ch);
    /* 輸出空格來代替空白 */
    printf("  %c  \n", ch);
    printf(" %c%c%c \n", ch, ch, ch);
    printf("%c%c%c%c%c\n", ch, ch, ch, ch, ch);
    printf(" %c%c%c \n", ch, ch, ch);
    printf("  %c  \n", ch);
    return 0;
}

10:超級瑪麗遊戲

這道題。。。直接輸出就能夠了。。。。code

#include<stdio.h>

int main(void)
{
    printf("                ********\n");
    printf("               ************\n");
    printf("               ####....#.\n");
    printf("             #..###.....##....\n");
    printf("             ###.......######              ###                 ###           ###           ###\n");
    printf("                ...........               #...#               #...#         #...#         #...#\n");
    printf("               ##*#######                 #.#.#               #.#.#         #.#.#         #.#.#\n");
    printf("            ####*******######             #.#.#               #.#.#         #.#.#         #.#.#\n");
    printf("           ...#***.****.*###....          #...#               #...#         #...#         #...#\n");
    printf("           ....**********##.....           ###                 ###           ###           ###\n");
    printf("           ....****    *****....\n");
    printf("             ####        ####\n");
    printf("           ######        ######\n");
    printf("##############################################################              ##################################\n");
    printf("#...#......#.##...#......#.##...#......#.##------------------#              #...#......#.##------------------#\n");
    printf("###########################################------------------#              ###############------------------#\n");
    printf("#..#....#....##..#....#....##..#....#....#####################              #..#....#....#####################\n");
    printf("##########################################    #----------#                  ##############    #----------#\n");
    printf("#.....#......##.....#......##.....#......#    #----------#                  #.....#......#    #----------#\n");
    printf("##########################################    #----------#                  ##############    #----------#\n");
    printf("#.#..#....#..##.#..#....#..##.#..#....#..#    #----------#                  #.#..#....#..#    #----------#\n");
    printf("##########################################    ############                  ##############    ############\n");
    return 0;
}

寫在最後

該博客僅供參考遊戲

相關文章
相關標籤/搜索