#第二章1
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define NAME "曾"
#define SURNAME "钰芝"
int main(){
printf("%s %s\n",NAME,SURNAME);
printf("%s\n%s\n",NAME,SURNAME);
printf("%s ",NAME);
printf("%s\n",SURNAME);
return 0;
}
#第二章2
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define NAME "曾钰芝"
#define ADDRESS "No.10 Hangzhou Xiaoshan Yaqian Huitouzhanglu"
int main(void) {
printf("%s\n",NAME);
printf("%s\n",ADDRESS);
return 0;
}
#第二章3
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章3
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define DAYS_PER_YEAR 365
int main(){
int age,days;
age = 18;
days = age*DAYS_PER_YEAR;
printf("You age is %d, and It is %d. \n",age,days);
return 0;
}
#第二章4
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章4
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int jolly(void);
int deny(void);
int main(void) {
jolly();
jolly();
jolly();
deny();
return 0;
}
int jolly(void){
printf("For he's a jolly good fellow!\n");
return 0;
}
int deny(void){
printf("WHich nobody can deny!\n");
return 0;
}
#第二章5
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章5
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int br(void);
int ic(void);
int main(void) {
br();
printf(", ");
ic();
printf(", \n");
br();
printf("\n");
return 0;
}
int br(void){
printf("Brazil, Russia");
return 0;
}
int ic(void){
printf("India, China");
return 0;
}
#第二章6
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章6
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int main(void) {
int toes;
toes = 10;
printf("The Variable toes = %d.\n",toes);
printf("double toes = %d\n",2*toes);
printf("toes' square = %d.\n",toes*toes);
return 0;
}
#第二章7
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章7
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#include<stdio.h>
int main(void) {
smile();smile();smile();
printf("\n");
smile();smile();
printf("\n");
smile();
return 0;
}
int smile(void){
printf("Smile!");
return 0;
}
#第二章8
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第二章8
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int one_three(void);
int two(void);
int main(void) {
printf("Starting now!!!:\n");
one_three();
printf("Go!\n");
return 0;
}
int one_three(void){
printf("three\n");
two();
printf("three\n");
return 0;
}
int two(void){
printf("two\n");
return 0;
}
#第三章1
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章1
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#include<float.h>
#include<limits.h>
int main(void) {
int big_int = 2147483647;
float big_float = 3.4e38;
float small_float = 10.0/3;
printf("The big int data is %d\n",big_int+1);
printf("The big float data is %f\n",big_float*10);
printf("The big float data is %f\n",small_float);
printf("The MAX float data is %f\n",FLT_MAX);
printf("The MAX int data is %1d\n",INT_MAX);
return 0;
}
#第三章2
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章2
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int main(void) {
int input;
printf("Enter a vaule of char int ASCII:");
scanf("%d,&input");
printf("You input vaule is %d, and char is %c\n",input,input);
return 0;
}
#第三章3
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章3
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int main(void) {
char ch = '\a';
printf("%c",ch);
printf("Starled by the sudden sound, Sally shouted, \n");
printf("\"By the Great Pumpkin,what was that!\"\n");
return 0;
}
#第三章4
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章4
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int main(void) {
float input;
printf("Enter a floating-point value:");
scanf("%f",&input);
printf("fixed-point notation: %f\n",input);
printf("exponential notation: %e\n",input);
printf("p notation: %a\n",input);
return 0;
}
#第三章5
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章5
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define SEC_PER_YEAR 3.156e7
int main(void) {
float second,year;
printf("Enter how many years old you are:");
scanf("%f",&year);
second = year*SEC_PER_YEAR;
printf("You are: %.1f years old.\n",year);
printf("And you are %e seconds old,too.\n",second);
return 0;
}
#第三章6
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章6
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define MASS_PER_MOLE 3.0e-23
#define MASS_PER_QUART 950
int main(void) {
float quart,quantity;
printf("Enter how many quart:");
scanf("%f",&quart);
quantity = quart*MASS_PER_QUART/MASS_PER_MOLE;
printf("There are %e molecule.\n",quantity);
return 0;
}
#第三章7
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章7
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define INCH_TO_CM 2.54
int main(void) {
float inch,cm;
printf("Enter the inch of your heigh:");
scanf("%f",&inch);
cm = inch*INCH_TO_CM;
printf("Hi ,your are %0.2f inch ,or %.2f cm heigh\n",inch,cm);
return 0;
}
#第三章8
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第三章8
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
#define PINT_CUP 2
#define CUP_OUNCE 8
#define OUNCE_SPOON 2
#define SPOON_TEA 3
int main() {
float pint,cup,ounce,spoon,tea_spoon;
printf("Enter how many cup:");
scanf("%f",&cup);
pint = cup/PINT_CUP;
ounce = cup*CUP_OUNCE;
spoon = OUNCE_SPOON;
tea_spoon = spoon*SPOON_TEA;
printf("%.1f cup equals %.1f pint, %.1f ounce, %.1f spoon, %.1f tea_spoon.\n",cup,pint,ounce,spoon,tea_spoon);
return 0;
}
#第四章1
/*
* @Author:曾钰芝
* @Date: 2020-11-15 15:36:11
* @LastEditTime: 2020-11-15 15:52:09
* @LastEditors: Please set LastEditors
* @Description: 书本第四章1
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。.c
*/
int main() {
char name[40];
char surname[40];
printf("Please input your first name:");
scanf("%s",name);
printf("Please input your last name:");
scanf("%s",surname);
printf("Hello, %s%s!!!",name,surname);
return 0;
}
#第四章2
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章2
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main() {
char name[40];
int width;
printf("Please input your name:");
scanf("%s",name);
width = printf("\"%s\"\n.",name);
width -= 4;
printf("\"%20s\".\n",name);
printf("\"%-20s\".\n",name);
printf("\"%*s\".",(width+3),name);
printf("\"%*s".",(width+3),name);
return 0;
}
#第四章3
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description:书本第四章3
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main() {
float input;
printf("Enter a float number:");
scanf("%f",&input);
printf("The input is %.1f or %.1e \n",input,input);
return 0;
}
#第四章4
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章4
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main() {
float heigh;
char name[40];
scanf("%s",name);
printf("Enter your name :");
scanf("%s",name);
printf("Hi %s, how tall you are( inch ):",name);
scanf("%f"&heigh);
printf("%s, you are %.3f feet tall \n",name,heigh\12.0)
return 0;
}
#第四章5
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章5
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main() {
float speed,size,time;
printf("Pleast input the net speed(megabits per second):");
scanf("%f",&speed);
printf("Pleast input the file size(megabyte):");
scanf("%f",&size);
time = size*8/speed;
printf("At %.2f megabits per second, a file of %.2f megabytes download in%.2f second.",speed,size,time);
return 0;
}
#第四章6
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章6
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main() {
char name[40],surname[40];
int wname, wsurname;
printt("Please input your first name:");
scanf("%s",name);
printf("Please input your last name:");
scanf("%s",surname);
wname = printf("%s",name);
printf(" ");
wsurname = printf("%s",surname);
printf("\n%*d %*d",wname,wname,wsurname,wsurname);
return 0;
}
#第四章7
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章7
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
#include<float.h>
int main() {
double d_third = 1.0/3.0;
float f_third = 1.0/3.0;
printf("float of one third(6) = %.6f\n",f_third);
printf("float of one third(12) = %.12f\n",f_third);
printf("double of one third(16) = %.16f\n",f_third);
printf("double of one third(6) = %.61f\n",d_third);
printf("double of one third(12) = %.121f\n",d_third);
printf("double of one third(16) = %.161f\n",d_third);
printf("FLT_DIG in float.h is %d\n",FLT_DIG);
printf("DBL_DIG in float.h is %d\n",DBL_DIG);
return 0;
}
#第四章8
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第四章8
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
#define GALLON_TO_LITRE 3.785
#define MILE_TO_KM 1.609
int main(){
float range,oil;
printf("Plaest input the range you traveled(in mile):");
scanf("%f",&oil);
printf("In UAS, your oil wear is %.1f M/G\n",range/oil);
printf("In Europe, your iol wear is %.1fL/100KM",(oil*GALLON_TO_LITRE)/(range*MILE_TO_KM));
return 0;
}
#第五章1
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章1
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
#define MIN_PER_HOU 60
int main(int argc, char *argv[]) {
int hours, minutes, input;
printf("CONVERT MINUTES TO HOURS!\n");
printf("PLEASE INPUT THE NUMBER OF MINUTES( <=0 TO QUIT ):");
scanf("%d",&input);
while(input >0){
hours = input/MIN_PER_HOU;
minutes = input&MIN_PER_HOU;
printf("CONVERT TO &d HOUR %d MINUTES\n",hours,minutes);
printf("PLEASE CONTINUE INPUT THE NUMBER OF MINUTES( <=0 TO QUIT):");
scanf("%d",&input);
}
printf("PROGRAM EXIT!\n");
}
#第五章2
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章2
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main(int argc, char *argv[]) {
int counter, i = 0;
printf("PRINT COUNTINUE 10 NUMBERS!\n");
printf("PLEASE INPUT THE START NUMBER :");
scanf("%d",&counter);
while(i++ < 11){
printf(" %d \n",counter++);
}
printf("PROGRAM EXIT!\n");
return 0;
}
#第五章3
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章3
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
#define WEEK_PER_DAY 7
int main(int argc,char *argv[]) {
int days, weeks, input;
printf("CONVERT DAYS TO WEEKS!\n");
printf("PLEASE INPUT THE NUMBER OF DAYS( <=0 TO QUIT):");
scanf("%d",&input);
while(input >0) {
weeks = input/WEEK_PER_DAY;
days = input&WEEK_PER_DAY;
printf("%d days are %d weeks, %d days\n",input,weeks,days);
printf("PLEASE INPUT THE NUMBER OF DAYS( <=0 TO QUIT ):");
scanf("%d",&input);
}
printf("PROGRAM EXIT!\n");
return 0;
}
#第五章4
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章4
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
#define FEET_TO_CM 30.48
#define INCH_TO_CM 2.54
int main(int argc, char *argv[]) {
int feet;
float inches, cm;
printf("CONVERT CM TO INCHES!\n");
printf("Enter the height in centimeters:");
scanf("%f",&cm);
while(cm > 0){
feet = cm/FEET_TO_CM;
inches = (cm/FEET_TO_CM)/INCH_TO_CM;
scanf("%f",&cm);
}
printf("PROGRAM EXIT!\n");
return 0;
}
#第五章5
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章5
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main(int argc, char *argv[]) {
int count = 0, sum= 0;
printf("Enter the number of days you work:");
scanf("%d",&count);
while(count > 0){
sum = sum +count--;
}
printf("You earned $ %d total!\n",sum);
printf("PROGRAM EXIT!\n");
return 0;
}
#第五章6
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章6
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main(int argc, char *argv[]) {
int count = 0, sum = 0;
printf("Enter the number of days you work:");
scanf("%d",&count);
while(count > 0);{
sum = sum +count * count;
count--;
}
printf("You earned $ %d total!\n",sum);
printf("PROGRAM EXIT!\n");
return 0;
}
#第五章7
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章7
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
double cubic(double n);
int main(int argc, char *argv[]) {
double input;
printf("Enter the double datum to calc cubic :");
scanf("%1f",&input);
cubic(input);
printf("PROGRAM EXIT!\n");
return 0;
}
double cubic(double n){
double t = n*n*n;
printf("The %1g's cubic is %1g !\n",n,t);;
return t;
}
#第五章8
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章8
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int main(int argc, char *argv[]) {
int first, second;
printf("This program computes moduli.\n");
printf("Enter an integer to server as the second operand:");
scanf("%d",&second);
printf("Now enter the first operand:");
scanf("%d",&second);
while(first > 0){
printf("%d %% %d is %d\n",first,second,(first%second));
printf("Enter next number for first operand( <= 0 to quit):");
scanf("%d",&first);
return 0;
}
}
#第五章9
/*
* @Author:曾钰芝
* @Date: 2020-11-15 16:16:26
* @LastEditTime: 2020-11-15 16:16:26
* @LastEditors: your name
* @Description: 书本第五章9
* @FilePath: \undefinedc:\Users\wangfuren\Desktop\秃头c\。。。。。。。。.c
*/
int Tempratures(double fahrenheit);
int main(int argc, char *argv[]) {
double input;
printf("This program convert farhenheit to celsius and kelvin.\n");
printf("Enter a fahrenheit to start : ");
while(scanf("%1f",&input == 1){
Temperatures(input);
printf("Enter next fahrenheit! ( q to quit):");
}
printf("Done!\n");
return 0;
}
int Temperatures(double fahrenheit){
const double F_TO_C = 32.0;
const double C_TO_K = 273.16;
double celsius ,kelvin;
celsius = 5.0/9.0*(fahrenheit - F_TO_C);
kelvin = celsius + C_TO_K;
printf("%.2f. fahrenheit, equal %.2f celuius, and %.2f kelvin\n",fahrenheit,celsius,kelvin);
return 0;
}
来源:oschina
链接:https://my.oschina.net/u/4776602/blog/4718135