C程序(5.3-5.7)

5 3     86_7

# include <stdio.h>

# define switch_1 3.785f      //1加仑约等于 3.785

# define switch_2 1.609f      //1英里约等于1.609公里

 

int main(void)

{

       float mile,gallon,litre;

       float a,b;

 

       printf("please enter the miles you went and the gallons you used:/n");

       scanf("%f%f",&mile,&gallon);

       a=mile/gallon;

       printf("one gallon can go % .1f miles./n",a);

       b=a*switch_2/switch_1;

       litre= 100.0f /b;

       printf("go 100 kilometres need % .1f litres./n",litre);

      

       return 0;

}

 

 

5 4     114_8

# include <stdio.h>

const double a=1.8;

const double b=32.0;

const double c=273.16;

int Temperature (double Fahren);

 

int main (void)

{

       double Fahrenheit;

       printf("Please enter a temperature,use Fahrenheit(q to quit):/n");

       while (scanf("%lf",&Fahrenheit)==1)

       {

              Temperature (Fahrenheit);

              printf("Please enter a temperature,use Fahrenheit(q to quit):/n");

       }

       return 0;

}

 

int Temperature (double Fahren)

{

       double Celsius,Kelvin;

       Celsius=a*Fahren+b;

       Kelvin=Celsius+c;

       printf("the temperature input is % .2f F./n",Fahren);

       printf("its Celsius is % .2f C./n",Celsius);

       printf("its Kelvin is % .2f K./n",Kelvin);

       return 0;

}

 

 

5 5       150_6

# include <stdio.h>

# include <string.h>     //提供strlen()函数

 

int main (void)

{

       char word[30];

 

       printf("Please enter a word./n");

       scanf("%s",word);

       printf("the word you enter is %s.",word);

       printf("/n");

 

       for(int i=strlen(word);i>=0;i--)

       {

              printf("%c",word[i]);

       }

       printf("/n");

 

       return 0;

}

 

 

 

5 6      150_8

# include <stdio.h>

float calculate (float,float);

 

int main(void)

{

       float a,b;

       printf("please enter two numbers(q to quit):/n");

 

       while ( scanf("%f%f",&a,&b)==2 )

       {

              printf("the result is %f./n",calculate(a,b));

              printf("please enter another two numbers(q to quit):/n");

       }

       return 0;

}

 

float calculate (float m,float n)

{

       float c,d;

       d=(m<n)?n-m:m-n;

       c=d/(m*n);

 

       return c;

}

 

 

 

5 7       150_11

# include <stdio.h>

double func1 (int);

double func2 (int);

 

int main (void)

{

       int terms;

       printf("please enter the number(q to quit):/n");

 

       while ( scanf("%d",&terms) )

       {

              printf("when terms=%d,func1=%f,func2=%f./n",

                        terms,func1(terms),func2(terms));

              printf("please enter other number(q to quit):/n");

       }

       return 0;

}

 

double func1 (int n1)

{

       double f1=0;

       for(n1;n1>=1;n1--)

       {

              f1+=1.0/n1;

       }

       return f1;

}

 

double func2 (int n2)

{

       double f2=0;

       int i;

 

       for(i=1;i<=n2;i++)

       {

              if(i%2==0)

                     f2+=(-1.0/i);

              else

                     f2+=1.0/i;

       }

       return f2;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值