部分习题代码丢失,需要请联系博主。
编译环境:Visual Studio 2017
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<float.h>
#include<math.h>
void lifang(double x);
void Temperatures(double a);
******************************************************************************
/* practice 1
void p4_1(void)
{
char last_name[20],first_name[20];
printf("Please input your name:");
printf("_____________\b\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%s %s", first_name,last_name);
printf("your name is %s %s", first_name,last_name);
system("pause");
}
/* practice 2
void p4_2(void)
{
char name[20];
int num;
printf("Please input your name:\n");
scanf("%s", name);
num = strlen(name);
printf("Your name is \"%s\"\n", name);
printf("Your name is \"%20s\"\n", name);
printf("Your name is \"%-20s\"\n", name);
printf("Your name is \"%*s\"\n",num+3,name);
system("pause");
}
/* practice 3
void p4_3(void)
{
float num=21.12345;
printf("Please input a float number:\n");
printf("The input is %3.1f or %.1e\n", num, num);
printf("The input is %+.3f or %.3E",num,num);
system("pause");
}
/* practice 4
void p4_4(void)
{
char name[20];
float old;
printf("Please input your name and years-old:\n");
scanf("%s %f", name, &old);
printf("%s, you are %.3f feet tall", name, old);
system("pause");
}
/* practice 5
void p4_5(void)
{
float speed, size;
printf("Please input the speed,size:\n");
scanf("%f %f", &speed, &size);
printf("At %.2f m per second, a file of %.2f m download in %.2f seconds\n",
speed, size, size / speed);
system("pause");
}
/* practice 7
void p4_7(void)
{
double a = 1.0 / 3.0;
float b = 1.0 / 3.0;
printf("a=%.6f,b=%.6f\n", a, b);
printf("a=%.12f,b=%.12f\n", a, b);
printf("a=%.16f,b=%.16f\n", a, b);
printf("float precision = %d digits\n", FLT_DIG);
printf("double precision = %d digits\n", DBL_DIG);
system("pause");
}
/* practice 8
void p4_8(void)
#define j2s 3.785
#define y2k 1.609
{
float distance, content;
printf("Please input distance and content:\n");
scanf("%f %f", &distance, &content);
printf("one jialun can suport %.1f mile\n", distance / content);
printf("one s can suport %.1f k\n", (j2s*distance)/(y2k*content));
system("pause");
}