# 請問一個程式C語言四則運算(要求至小數)的問題

請問如何利用四個functions計算二個整數的和,差,積,商(求至小數後二位)

### 1 Answer

Rating

- 9 years agoFavorite Answer
#include<stdio.h>

#include<stdlib.h>

int plus(int a,int b){

return a+b;

}

int minus(int a,int b){

return a-b;

}

int multi(int a,int b){

return a*b;

}

double equal(int a,int b){

return (double)a/b;

}

int main(void){

int a,b;

int P,M,X;

double E;

printf("請輸入兩個整數(ex : 1 2) : ");

scanf("%d %d",&a,&b);

P = plus(a,b);

M = minus(a,b);

X = multi(a,b);

E = (double)equal(a,b);

printf("和 : %d 差 : %d 積 : %d 商 : %.2f",P,M,X,E);

system("pause");

return 0;

}

Source(s): 自己

Still have questions? Get your answers by asking now.