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

第一题
#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",&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);
}


  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值