C Primer Plus 第六章 编程练习 1-8题

    xiaoxiao2021-03-25  87

    第一题 #include<stdio.h> int Nu = 26; int main(void) { char letters[Nu]; char EnterChar = 'a'; char EndChar = 'z'; int counts = 0; while(EnterChar != EndChar+1) { letters[counts] = EnterChar; ++counts; ++EnterChar; } printf("%s\n",letters); return 0; } 第二题 #include<stdio.h> const int Nu = 5; const char ShowChar = '$'; int main(void) { for(int i = 0 ; i < Nu ; ++i) { for(int j = 0 ; j <= i ; ++j) printf("%c",ShowChar); printf("\n"); } return 0; } 第三题 #include<stdio.h> const int ROWS = 6; int main(void) { char FirstChar = 'F'; for(int i = 0 ; i < ROWS ; ++i) { for(int j = 0 ; j <= i ; ++j) printf("%c",FirstChar-j); printf("\n"); } return 0; } 第四题 #include<stdio.h> const int ROWS = 5; int main(void) { char FirstChar = 'A'; for(int i = 1 ; i <= ROWS ; ++i) { for(int Space = 0 ; Space < ROWS-i ; ++Space) //First Loop To Space printf(" "); // My OptionSystem Looks Like Don't Support "\b",I Only Use " " Replace "\b".... for(int UpLetter = 0 ; UpLetter < i ; ++UpLetter) //second Loop To Ascend Letter printf("%c",FirstChar+UpLetter); for(int DownLetter = i-2 ; DownLetter >= 0 ; --DownLetter) //Thrid Loop To Descend Letter printf("%c",FirstChar+DownLetter); printf("\n"); } return 0; } 第五题 #include<stdio.h> int main(void) { long int FirstNumber; long int LastNumber; printf("PLease Input First Number:"); scanf("%ld",&FirstNumber); printf("Please Input Last NUmber:"); scanf("%ld",&LastNumber); printf("sss\n","Int","Pow","Cub"); for(long int i = FirstNumber ; i <= LastNumber ; ++i) printf("ldldld\n",i,i*i,i*i*i); return 0; } 第六题 #include<stdio.h> #include<string.h> const int Len = 20; int main(void) { char TestWord[Len]; printf("PLease Input Any Word(Max: 20 Letters):"); scanf("%s",TestWord); int Lenght = strlen(TestWord); for(int i = Lenght-1 ; i >= 0 ; --i) printf("%c",TestWord[i]); return 0; } 第七题 #include<stdio.h> #include<math.h> // For abs() int main(void) { double FirstNumber; double SecondNumber; int Switch_1; int Switch_2; printf("Please Input Any Double:"); Switch_1 = scanf("%lf",&FirstNumber); printf("PLease Input Another Double:"); Switch_2 = scanf("%lf",&SecondNumber); while(Switch_1 == 1 && Switch_2 == 1) { printf("%.2f\n",fabs(FirstNumber-SecondNumber) / (FirstNumber * SecondNumber)); printf("Please Input Any Double:"); Switch_1 = scanf("%lf",&FirstNumber); printf("PLease Input Another Double:"); Switch_2 = scanf("%lf",&SecondNumber); } printf("Done\n"); return 0; } 第八题 #include<stdio.h> #include<math.h> // For abs() double pt(double i , double j); int main(void) { double FirstNumber; double SecondNumber; int Switch_1; int Switch_2; printf("Please Input Any Double:"); Switch_1 = scanf("%lf",&FirstNumber); printf("PLease Input Another Double:"); Switch_2 = scanf("%lf",&SecondNumber); while(Switch_1 == 1 && Switch_2 == 1) { printf("%.2f\n",pt(FirstNumber,SecondNumber)); printf("Please Input Any Double:"); Switch_1 = scanf("%lf",&FirstNumber); printf("PLease Input Another Double:"); Switch_2 = scanf("%lf",&SecondNumber); } printf("Done\n"); return 0; } double pt(double i , double j) { return fabs(i-j) / (i*j); }
    转载请注明原文地址: https://ju.6miu.com/read-15166.html

    最新回复(0)