0

私はこのコードを持っています:

#include<stdio.h>
#include<conio.h>
#include<math.h>

float sinfa(num1, num2)
{
    float fc;
    float powers;
    if(num1 == ""){
    powers = pow(num2,4);
    }else{
    powers = pow(num1,4);
    }
    fc = sin(num1-powers+1);
    return (fc);
}

float tp(fa,fb,num1,num2)
{
    float p;
    float fm2 = fa*num2;
    float fm1 = fb*num1;
    p = (fm2-fm1)/(fa-fb);
    printf("%f",fa);
    return (p);
}

float main()
{
double num1;
double num2;
float fa;
float fb;
float p1;

    clrscr();
    printf("Enter number 1: \n");
    scanf("%d", &num1);
    getch();
    printf("Enter number 2: \n");
    scanf("%d", &num2);
    getch();
    clrscr();
    fa = sinfa(num1);
    printf("%f \n",fa);
    getch();
    fb = sinfa(num2);
    printf("%f",fb);
    getch();
    clrscr();
    p1 = tp(fa,fb,num1,num2);
    printf("%f",p1);
    getch();

}

関数tpから0を取得し続けましたが、アイデアを送信したときにパラメーターが入力されないのはなぜですか?sinfaの場合、パラメーターが送信され、値が返されるため

ありがとうございました

4

2 に答える 2

4

You need to give types to the function parameters.

float tp(float fa,float fb,int num1,int num2)

Otherwise they are considered int and that leads to confusing effects.

Similarly you should fix

float sinfa(int num1, int num2)

This wont cause a problem, but it is always good to be explicit about what you mean.

于 2013-01-28T03:46:47.577 に答える
3

常に1つのことを念頭に置いて、関数宣言および関数定義時に変数のデータ型に言及する習慣をつけてください。ここでは、タイプについて言及していません。これは、それをデフォルトのデータタイプと見なしていることを意味しますint

float tp(fa,fb,num1,num2)
         ^^missing data type at all parameter, mention data type
于 2013-01-28T03:49:31.043 に答える