//第 1 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
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 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
char name[40];
int width;
printf("Please input your name:") ;
scanf("%s", name);
width = printf("\"%s\"\n.", name);
width -= 4;
printf("\"%20s\".\n", name);
return 0;
}
//第 3 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
float input;
printf("Enter a float number:");
scanf("%f", &input);
printf("The input is %.1f or %.1e \n", input, input);
return 0;
}
//第 4 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
float heigh;
char name[40];
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 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
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 seconds.",
speed, size, time);
return 0;
}
//第 6 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
char name[40], surname[40];
int wname, wsurname;
printf("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 题
#include <stdio.h>
#include <float.h>
int main(void)
{
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("float of one third(16) = %.16f\n", f_third);
printf("double of one third(6) = %.6lf\n", d_third);
printf("double of one third(12) = %.12lf\n", d_third);
printf("double of one third(16) = 8.16lf\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 题
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define GALLON_TO_LITRE 3.785
#define MILE_TO_KM 1.609
int main(void)
{
float range, oil;
printf("Pleast input the range you traveled(in mile):");
scanf("%f", &range);
printf("Pleast input the oil you spend(in gallon):");
scanf("%f", &oil);
printf("In UAS, your oil wear is %.1f M/G\n", range / oil);
printf("In Europe, your oil wear %.1fL/100KM",
(oil * GALLON_TO_LITRE) / (range * MILE_TO_KM));
return 0;
}