C Primer Plus Sixth Edition (Chinese Edition) Chapter 2 (Perfect Revised Edition) Programming Practice Answers

//The code written by this blogger is only for readers' reference;

//If you have any shortcomings, please raise them, and the blogger will do their best to modify;

//Attach the programming practice questions after class;

//If it is useful to you, please like or share it with others;



//2.12 - 1.c

#include <stdio.h>

int main(void)
{
    
    
    printf("Black Clover\n");
    printf("Black\nClover\n");
    printf("Black ");
    printf("Clover\n");
    
    return 0;
}

//-------------

//2.12 - 2.c

#include <stdio.h>
int main(void)
{
    
    
    printf("My name is Black Clover.\n");
    printf("My address is in China.\n");
    
    return 0;
}

//-------------

//2.12 - 3.c

#include <stdio.h>

int main(void)
{
    
    
    int days;
    int age = 18;
    int days_per_year = 365;

    days = age * days_per_year;
    printf("I am %d years old.\n", age);
    printf("Days are %d.\n", days);

    return 0;
}

//-------------

//2.12 - 4.c

#include <stdio.h>

void jolly(void);
void deny(void);

int main(void)
{
    
    
    jolly();
    jolly();
    jolly();
    deny();

    return 0;
}

void jolly(void)
{
    
    
    printf("For he's a jolly good fellow!\n");
    return;
}

void deny(void)
{
    
    
    printf("Which nobody can deny!\n");
    return;
}

//-------------

//2.12 - 5.c

#include <stdio.h>

void br(void);
void ic(void);

int main(void)
{
    
    
    br();
    printf(", ");
    ic();
    printf("\n");
    ic();
    printf(",\n");
    br();

    return 0;
}

void br(void)
{
    
    
    printf("Brazil, Russia");
    return;
}

void ic(void)
{
    
    
    printf("India, China");
    return;
}

//-------------

//2.12 - 6.c

#include <stdio.h>

int main(void)
{
    
    
    int toes = 10;

    printf("toes = %d\n", toes);
    printf("toes * 2 = %d\n", toes * 2);
    toes = toes * toes;
    printf("toes ^ 2 = %d\n", toes);

    return 0;
}

//-------------

//2.12 - 7.c

#include <stdio.h>

void smile(void);

int main(void)
{
    
    
    smile();
    smile();
    smile();
    printf("\n");
    smile();
    smile();
    printf("\n");
    smile();
    printf("\n");

    return 0;
}

void smile(void)
{
    
    
    printf("Smile!");
    return;
}

//-------------

//2.12 - 8.c

#include <stdio.h>

void one_three(void);
void two(void);

int main(void)
{
    
    
    printf("Starting now:\n");
    one_three();
    printf("Done!\n");

    return 0;
}

void one_three(void)
{
    
    
    printf("one\n");
    two();
    printf("three\n");
    return;
}

void two(void)
{
    
    
    printf("two\n");
    return;
}

//-------------

//----------------------------April 2, 2020-------------- -----------------

Guess you like

Origin blog.csdn.net/m0_46181359/article/details/105279037