/* 4.1 */
#include<stdio.h>
int main(void)
{
char ming[20];
char xing[20];
scanf("%s %s",&ming,&xing);
printf("%s %s",ming,xing);
return 0;
}
/* 4.1 */
#include<stdio.h>
#include<string.h>
int main(void)
{
char xingming[40];
scanf("%s",&xingming);
int len_xingming;
len_xingming=strlen(xingming);
printf("\"%s\"\n",xingming);
printf("\"%20s\"\n",xingming);
printf("\"%-20s\"\n",xingming);
printf("%*s\n",len_xingming+3,xingming);
return 0;
}
/* 4.3 */
#include<stdio.h>
int main(void)
{
double number1;
double number2;
printf("Enter a float number.\n");
scanf("%lf",&number1);
number2=number1;
printf("The input is %2.1lf or %.1e.\n",number1,number1);
printf("The input is %+5.3lf or %5.3E.",number2,number2);
return 0;
}
/* 4.4 */
#include<stdio.h>
int main(void)
{
float height;
char name[40];
printf("Hello,please enter your height(feet).\n");
scanf("%f",&height);
printf("Then,please enter your name.\n");
scanf("%s",&name);
printf("%s,you are %.3f feet tall.\n",name,height);
printf("In centimenter:%fcm\n",height*2.54);
printf("IN meter:%fm",height*2.54*100);
return 0;
}
/* 4.5 */
#include<stdio.h>
int main(void)
{
float speed;
float bytes;
printf("What's speed when you download(Mb/s)?");
scanf("%f",&speed);
printf("How large is the file size(MB)?");
scanf("%f",&bytes);
printf("At %.2f megabits per second, a file of %.2fmegabytes download in %.2f seconds\n",
speed,bytes,(8*bytes)/speed);
return 0;
}
/* 4.6 */
#include<stdio.h>
#include<string.h>
int main(void)
{
char first_name[30];
char last_name[30];
int length_first;
int length_last;
printf("你的用户名是什么?\n");
scanf("%s",first_name);
printf("你的姓名是?\n");
scanf("%s",last_name);
length_first = strlen(first_name);
length_last = strlen(last_name);
printf("%s %s\n",first_name,last_name);
printf("%*d %*d\n",length_first,length_first,length_last,length_last);
printf("%s %s\n",first_name,last_name);
printf("%-*d %-*d",length_first,length_first,length_last,length_last);
return 0;
}
/* 4.7 */
#include<stdio.h>
#include<float.h>
int main(void)
{
double x = 1.0/3.0;
float y = 1.0/3.0;
printf("*%.6lf*\n*%.12lf*\n*%.16lf*\n",x,x,x);
printf("*%.6f*\n*%.12f*\n*%.16f*\n",y,y,y);
printf("FLT_DIG = %d\n",FLT_DIG);
printf("DBL_DIG = %d\n",DBL_DIG);
return 0;
}
/* 4.8 */
#include<stdio.h>
#define PER_JL 3.785
#define PER_YL 1.609
int main(void)
{
const double MILES = 3.785;
double m;
double g;
printf("输入旅程距离和消耗的汽油量.\n");
scanf("%lf %lf",&m,&g);
printf("Consumed one gasoline oil can drive %.1lf miles.\n",m/g);
printf("Translate in rise/km: %.1lf",(g*PER_JL)/(PER_YL*m*100));
return 0;
}