C Primer Plus 第四章 编程练习 1-7题

第一题

#include<stdio.h>
const int LenOfName = 20;
int main(void)
{
char firstName[LenOfName];
char lastName[LenOfName];

printf("PLease Enter Your First Name:");
scanf("%s",firstName);
printf("PLease Enter Your Last Name:");
scanf("%s",lastName);

printf("Hi,%s.%s",firstName,lastName);

return 0;
}

第二题

#include<stdio.h>
#include<string.h>
int main(void)
{
char TestName[20];
printf("Please Enter Your Name:");
scanf("%s",TestName);

printf("\"%s\"\n",TestName);
printf("\"%20s\"\n",TestName);
printf("\"%-20s\"\n",TestName);

int Len = strlen(TestName);
printf("%*s",Len+3,TestName);

return 0;
}

第三题

#include<stdio.h>
int main(void)
{
double TestNumber;
printf("Please Enter An Double To Test:");
scanf("%lf",&TestNumber);
printf("The input is %lf or %e.",TestNumber,TestNumber);

return 0;
}

第四题

#include<stdio.h>
int main(void)
{
float HeightForYou;
printf("Please Enter Your Tall(cm):");
scanf("%f",&HeightForYou);
printf("You Are %f M Tall!",HeightForYou/100);

return 0;
}

第五题

#include<stdio.h>
#include<string.h>
int main(void)
{
char FirstName[20];
char LastName[20];
printf("PLease Enter Your First Name:");
scanf("%s",FirstName);
printf("Please Enter Your Last Name:");
scanf("%s",LastName);

int LenForFirstName = strlen(FirstName);
int LenForLastName = strlen(LastName);
printf("%s %s\n",FirstName,LastName);
printf("%*d %*d\n",LenForFirstName,LenForFirstName,LenForLastName,LenForLastName);
printf("%s %s\n",FirstName,LastName);
printf("%-*d %-*d\n",LenForFirstName,LenForFirstName,LenForLastName,LenForLastName);

return 0;
}

第六题

#include<stdio.h>
#include<float.h>
int main(void)
{
double Dou = 1.0/3.0;
float Flo = 1.0/3.0;
printf("double : %.4lf float : %.4f\n",Dou,Flo);
printf("double : %.12lf float : %.12f\n",Dou,Flo);
printf("double : %.16lf float : %.16f\n",Dou,Flo);

printf("DBL_DIG : %d FLT_DIG : %d\n",DBL_DIG,FLT_DIG);

return 0;
}

第七题

#include<stdio.h>
const double GL = 3.785;
const double YL = 1.609;
int main(void)
{
double LongForCar;
double GasForCar;
printf("PLease Enter The Long:");
scanf("%lf",&LongForCar);
printf("PLease Enter The Gas What Had Been Cost:");
scanf("%lf",&GasForCar);

printf("KMT Is %.1lf\n",LongForCar/GasForCar);
printf("KMT Is %.1lf\n",(GasForCar*GL) / (LongForCar*YL) * 100);

return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值