为什么我的程序一直在计算相同的力?我使用的公式是正确的,但是我不知道为什么我一直得到127达因的力。任何帮助都将不胜感激
#include <stdio.h>
#include <math.h>
const double gravity_constant = 6.673;
void force_calculate(double a, double b, double c, double d);
void input(double *a, double *b, double *c);
void display(double a, double b, double c, double d);
int main(int argc, char * argv[])
{
double mass_1 = 0;
double mass_2 = 0;
double distance = 0;
double force = 0;
input(&mass_1, &mass_2, &distance);
force = force_calculate(mass_1, mass_2, distance, force);
display(mass_1, mass_2, distance, force);
return 0;
}
void force_calculate(double a, double b, double c, double d)
{
d = (gravity_constant*a*b)/(c*c);
return;
}
void input(double *a, double *b, double *c)
{
printf("What is the first mass in grams?\n");
scanf("%lf", a);
printf("What is the second mass in grams?\n");
scanf("%lf", b);
printf("What is the distance between the two masses in centimeters\n");
scanf("%lf", c);
}
void display(double a, double b, double c, double d)
{
printf("%fg is the first mass\n", a);
printf("%fg is the second mass\n", b);
printf("%fcm is the distance between the two masses\n", c);
printf("%f is the force in dynes between both masses\n", d);
return;
}
最佳答案
您应该返回该值,以便可以对其进行赋值(确保它也是正确的类型)。此外,可以在此处取消使用力,因为这是计算的结果。
force = force_calculate(mass_1, mass_2, distance);
...
double force_calculate(double a, double b, double c)
{
return (gravity_constant*a*b)/(c*c);
}
关于c - 群众之间的引力,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19505894/