#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/************************************/
/* practice 1 第四章作业 */
/***********************************/
void p4_1()
{
char name[20];
char fristName[20];
printf("Please Enter your name:");
scanf("%s",name);
printf("Please Enter your fristname:");
scanf("%s",fristName);
printf("%s,%s",name,fristName);
}
/************************************/
/* practice 2 第四章作业 */
/***********************************/
void p4_2()
{
char name[20];
int len=strlen(name)+3;
printf("Please Enter your name:");
printf("%d",len);
printf("\"%s\"\n",name);
printf("\"%20s\"\n",name);
printf("\"%-20s\"\n",name);
printf("\"%*s\"\n",len,name);
}
/************************************/
/* practice 3 第四章作业 */
/***********************************/
void p4_3()
{
float num1,num2;
printf("Please Enter a float number:");
scanf("%f",&num1);
printf("a.The input is %.1f or %.1e\n",num1,num1);
printf("Please Enter other float number:");
scanf("%f",&num2);
printf("b.The input is +%.3f or %.3e\n",num2,num2);
}
/************************************/
/* practice 4 第四章作业 */
/***********************************/
void p4_4(void)
{
float height;
char name[20];
printf("Please Enter your height:");
scanf("%f",&height);
printf("Please Enter your name:");
scanf("%s",name);
printf("%s, you are %f feet tall",name,height);
}
/************************************/
/* practice 5 第四章作业 */
/***********************************/
void p4_5(void)
{
float velocity, size_file, time;
printf("Please input the download velocity(Mb/s)、The file size:\n");
scanf("%f,%f",&velocity,&size_file);
time = size_file*8 / velocity;
printf("At %.2f megabits per second, a file of %.2f megabytes\n downloads in %.2f seconds",velocity,size_file,time);
}
/************************************/
/* practice 6 第四章作业 */
/***********************************/
void p4_6(void)
{
char lastname[20];
char firstname[20];
printf("Please input last-name:");
scanf("%s",lastname);
printf("Please input first-name:");
scanf("%s",firstname);
printf("%s %s\n",lastname,firstname);
printf("%*d %*d\n",strlen(lastname),strlen(lastname),strlen(firstname),strlen(firstname));
printf("********************************************\n");
printf("%s %s\n",lastname,firstname);
printf("%-*d %-*d\n",strlen(lastname),strlen(lastname),strlen(firstname),strlen(firstname));
}
int main()
{
p4_6();
return 0;
}