如何将变量传递给另一个函数?

Zak*_*ako -7 c variables function

我不知道如何将变量从main()传递给另一个函数.我有这样的事情:

main()
{
  float a, b, c;

  printf("Enter the values of 'a','b' and 'c':");
  scanf("%f %f %f",&a,&b,&c);
}

double my_function(float a,float b,float c)
{
  double d;

      d=a+b+c
      bla bla bla bla
Run Code Online (Sandbox Code Playgroud)

如何将a,b和c从main传递给my_function?现在,程序在scanf()上停止,并在我输入值后直接完成.

我在这里看到了不同的例子,但他们对我帮助不大.

Rav*_*ale 5

仅仅通过传递参数调用函数a,bc.句法:

retval = function_name(parameter1,parameter2,parameter3); //pass parameters as required
Run Code Online (Sandbox Code Playgroud)

像这样:

int main(void)
{
    float a, b, c;
    double d;

    printf("Enter the values of 'a','b' and 'c': ");
    if (scanf("%f %f %f",&a,&b,&c) == 3)
    {
        d = my_function(a, b, c);
        printf("Result: %f\n", d);
    }
    else
        printf("Oops: I didn't understand what you typed\n");      
}
Run Code Online (Sandbox Code Playgroud)