题目:6.8 编写一个程序, 要求用户输入两个浮点数, 并打印两数之差除以两数乘积的结果。 在用户输入非数字之前, 程序应循环处理用户输入的每对值。
#include<stdio.h>
#include <string.h>
#define NUM 400
int main()
{
int i=0;
char ch[NUM];
printf("Please enter the word you want to print: ");
scanf("%s",ch);
printf("\nPrint the word in reverse order:");
for(i=strlen(ch); i>=0; i--)
printf("%c",ch[i]);
printf("\n");
return 0;
}
运行结果:以2.0 3.0 和3.0 2.0 为例
验证:
题目:6.9 修改练习8, 使用一个函数返回计算的结果。
#include<stdio.h>
double caculation(double a,double b);
int main()
{
double a,b;
printf("Please enter the decimal values of a and b: ");
while(scanf("%lf %lf",&a,&b)==2)
{
printf("(a-b)/(a*b)=%.3lf\n",caculation(a,b));
printf("Please enter the decimal values of a and b(Non-digit exit):");
}
printf("Enter error or bye!");
return 0;
}
double caculation(double a,double b)
{
return (a-b)/(a*b);
}
备注:自己写的,也可能有问题,大家一起交流呀