程式 語法錯誤 尋求解答

這是我的作業

想辦法利用最少的變數來表現a ,b相乘與相除 同時獨立出乘與除兩個函數

以下是我的寫法

#include "stdio.h"

float a,b;

void main(void)

void sum(void)

void sub(void)

float sum(a,b)

{

return a*b;

}

float sub(a,b)

{

return a/b;

}

{

printf("Enter two words. This program will output the sum and subtract of two numbers.\n");

scanf_s("%f",&a);

printf("\n");

scanf_s("%f",&b);

printf("\n");

printf("The product of two numbers is %d.\n ",sum(a,b));

printf("The first number dividing the second is %d.\n ",sub(a,b));

}

我不知道錯在哪? 請幫我解答 謝謝

3 Answers

Rating
  • 小玉
    Lv 7
    1 decade ago
    Favorite Answer

    #include <stdio.h>

    #include <stdlib.h>

    float sum(float a, float b); //宣告函式

    float sub(float a, float b);

    void main(void)

    {

    float a,b;

    printf("Enter two words. This program will output the sum and subtract of two numbers.\n");

    scanf("%f",&a);

    printf("\n");

    scanf("%f",&b);

    printf("\n");

    printf("The product of two numbers is %f.\n",sum(a,b));

    printf("The first number dividing the second is %f.\n",sub(a,b));

    system("pause"); //程式暫停

    }

    float sum(float a, float b)

    {

    return a*b;

    }

    float sub(float a, float b)

    {

    return a/b;

    }

  • 1 decade ago

    所以呢??

  • 鴨子
    Lv 6
    1 decade ago

    哇! 錯好多!

Still have questions? Get your answers by asking now.