题目:6.8 编写一个程序, 要求用户输入两个浮点数, 并打印两数之差除以两数乘积的结果。 在用户输入非数字之前, 程序应循环处理用户输入的每对值。
#include<stdio.h>
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",(a-b)/(a*b));
printf("Please enter the decimal values of a and b(Non-digit exit):");
}
printf("Enter error or bye!");
return 0;
}```
运行结果:
备注:自己写的,也可能有问题,大家一起交流呀
错误代码记录:
```c
#include<stdio.h>
#include <string.h>
#define NUM 10
int main(){
int i,j=0;
char ch[NUM];
printf("Please enter the word you want to print: ");
for(i=0;i<=strlen(ch);i++)
{scanf("%c",&ch[i]);}
printf("\n");
for(j=strlen(ch);j>=0;j--)
{printf("%c",ch[j]);}
printf("\n");
return 0;
}