您的位置:首页 > 编程语言

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

2017-03-09 20:01 357 查看
第一题
#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("%10s%10s%10s\n","Int","Pow","Cub");
for(long int i = FirstNumber ; i <= LastNumber ; ++i)
printf("%10ld%10ld%10ld\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",&a
4000
mp;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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: