C Primer Plus 第六章 编程练习 9-16题

第九题
#include
int SumOfSquare(int min , int max);
int main(void)
{
  int MaxInt;
  int MinInt;
  printf("PLease Input UpperLint Number:");
  scanf("%d",&MaxInt);
  printf("PLease Input LowerLint Number:");
  scanf("%d",&MinInt);
  while(MinInt < MaxInt)
  {
    printf("The Sums Of The Qquares From %d to %d is %d.\n",MinInt,MaxInt,SumOfSquare(MinInt,MaxInt));
    printf("PLease Input UpperLint Number:");
    scanf("%d",&MaxInt);
    printf("PLease Input LowerLint Number:");
    scanf("%d",&MinInt);
  }

  printf("Done.\n");

 return 0;
}
  
int SumOfSquare(int min , int max)
{
  int sums = 0;
  for(int i = min ; i <= max ; ++i)
    sums += i*i;
  return sums;
}


第十题
#include
const int Len = 8;
int main(void)
{
  int ShowInt[Len];
  for(int i = 0 ; i < Len ; ++i)
  {
    printf("PLease Enter %dth Ingeter:",i+1);
    scanf("%d",ShowInt+i);
  }

  for (int i = Len-1 ; i >= 0 ; --i)
    printf("%d",ShowInt[i]);

 return 0;
}


第十一题
#include
const double LIMITS = 998.0;
const double PT = 1.0;
enum Symbol {plus,minus};   // :)
double SumOfList(double limits, enum Symbol S);
int main(void)
{
  double limit;
  enum Symbol PL = plus;
  enum Symbol MI = minus;
  printf("Please Input Any Integer:");
  scanf("%lf",&limit);
  while(limit <= LIMITS)
  {
    printf("Sum(plus) is %lf\n",SumOfList(limit,PL));
    printf("Sum(minus) is %lf\n",SumOfList(limit,MI));
    printf("Please Input Any Integer:");
    scanf("%lf",&limit);
  }

 return 0;
}
double SumOfList(double limits , enum Symbol S)
{
  double sums = 0;
  for(double i = PT ; i <= limits ; i+=1.0)
  {
    if((int)i%2 == 1)
      sums += PT/i;
    if((int)i%2 == 0)
    {
      if(S == plus)
        sums += PT/i;
      if(S == minus)
        sums -= PT/i;
     }
  }
  return sums;
}


第十二题
#include
#include
const int Len = 8;
int main(void)
{
  int arr[Len];
  for(int i = 0 ; i < Len ; ++i)
    arr[i] = pow(2,i);
 
  int counts = 0;
  do
  {
    printf("%d\n",arr[counts]);
    ++counts;
  }while(counts


第十三题
#include
const int LEN = 8;
int main(void)
{
  double CustomArr[LEN];
  double SumArr[LEN];
  for(int i = 0 ; i < LEN ; ++i)
  {
    printf("Please Input %dth:",i+1);
    scanf("%lf",CustomArr+i);
  }

  SumArr[0] = CustomArr[0];
  for(int i = 1 ; i < LEN ; ++i)
    SumArr[i] = SumArr[i-1] + CustomArr[i];

  for(int i = 0 ; i < LEN ; ++i)
    printf("%6.2lf",CustomArr[i]);
  printf("\n");   // For \n
  for(int i = 0 ; i < LEN ; ++i)
    printf("%6.2lf",SumArr[i]);

 return 0;
}


第十四题
#include
const int MaxLen = 255;
int main(void)
{
  char WordList[MaxLen];
  int Len = 0;
  printf("Please Input Any Word:");
  do
  {
    scanf("%c",WordList+Len);
    ++Len;
  }
  while(WordList[Len-1] != '\n' && Len <= MaxLen);   //input

  printf("Change List Of Word:\n");  //output
  for(int i = Len-1 ; i >=0 ; --i)
    printf("%c",WordList[i]);

 return 0;
}


第十五题
#include
const double Capital = 100;
const double Interest_Daphne = 0.1;
const double Interest_Deirdre = 0.05;
int main(void)
{
  int years = 0;
  double Daphne = Capital;
  double Deirdre = Capital;
  do
  {
     ++years;
     Daphne += Capital * Interest_Daphne;
     Deirdre = Deirdre * (1 + Interest_Deirdre);
  }
  while(Deirdre <= Daphne);

  printf("%d Years Later ,Deridre Get %.2lf$,Daphne Get %.2lf$.",years,Deirdre,Daphne);

 return 0;
}


第十六题
#include
const double GetInterest = 1.08;
const double Cost = 100000;
int main(void)
{
  double Capital = 1000000;
  int years = 0;
  do
  {
    ++years;
    Capital *=GetInterest;
    Capital -= Cost;
  }
  while(Capital >= 0);

  printf("%d Years Later, He Cost Capital.",years);

 return 0;
}


你可能感兴趣的:(c语言)