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

    xiaoxiao2021-03-25  81

    第一题

    #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("\" s\"\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;}

    转载请注明原文地址: https://ju.6miu.com/read-15473.html

    最新回复(0)