第一章:初识C语言

第一题

image-20210218180036499

#include<stdio.h>
int main(void){
double inch = 0;
printf("Please enter the inchs:");
scanf("%lf", &inch);
printf("\nThe inch is equal to %lf cm.", 2.64 * inch);
return 0;
}

第二章:C语言概述

第一题

image-20210218165356250

#include<stdio.h>
int main(void){
printf("MINT Planetarian\n");
printf("MINT\nPlanetarian\n");
printf("MINT ");
printf("Planetarian\n");
return 0;
}

第二题

image-20210218170108840

#include<stdio.h>
int main(void){
printf("My name is: ");
printf("MINT Planetarian\n");
printf("I come from ");
printf("CHINA\n");
return 0;
}

第三题

image-20210218170307366

#include<stdio.h>
int main(void){
int old = 21;
printf("I am %d years old.\n",old);
printf("I have lived %d days.",365*old);
return 0;
}

补充:若考虑闰年问题,代码见下:

#include<stdio.h>
int run(int old, int year);

int main(void){
int old = 21;
int year = 1999;
int days;
printf("I am %d years old.\n",old);
printf("I have lived %d days.",run(old,year)*366 + (old - run(old,year)) * 365);
return 0;
}

int run(int old, int year){
if(year%4 == 0)
return old/4 + 1;
else{
if(old%4 == 0 || old < 4)
return old/4;
else
return old/4 + 1;
}
}

第四题

#include<stdio.h>
void jolly(void);
void deny(void);

int main(void){
int i=0;
for(i ;i<3 ;i++)
jolly();
deny();
return 0;
}

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

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

第五题

image-20210218175412720
#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");
}

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

第六题

image-20210218175914953

#include<stdio.h>
int main(void){
int toes = 10;
printf("num: %d\nsquare: %d\ncube: %d\n", toes, toes*toes, toes*toes*toes);
return 0;
}

第七题

image-20210218195922681
#include<stdio.h>
void smile(void);

int main(void){
int i = 0;
smile(); smile(); smile();
printf("\n");
smile(); smile();
printf("\n");
smile();
return 0;
}

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

第八题

image-20210218200616031
#include<stdio.h>
void one_three(void);
void two(void);

int main(void){
printf("starting now:\n");
onethree();
printf("done!");
return 0;
}

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