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;
}