roberthsu2003 / cAndC-

51 stars 18 forks source link

請將以下的數學運算式,使用自訂的function計算出結果 #52

Open roberthsu2003 opened 1 week ago

roberthsu2003 commented 1 week ago
截圖 2024-09-08 中午12 00 39
edward200897 commented 1 week ago
#include <iostream>
#include <math.h>

using namespace std;

int fun1(int x, int y){
  return pow(x, 3) + 3 * pow(x, 2) * y + 3 * x * pow(y, 2) + pow(y, 3);
}

int main() { 
  for(int x = 1; x < 5; x++){
    for(int y = 1; y < 5; y++){
      printf("f(%d, %d) = %d\n", x, y, fun1(x, y));
    }
  }
}
Gin-4869 commented 1 week ago
#include <iostream>
#include <math.h>

using namespace std;

int fun(int x, int y){
  int f = pow(x, 3) + 3 * pow(x, 2) * y + 3 * x * pow(y, 2) + pow(y, 3);
  return  f;
}

int main() { 
  for(int x = 1; x <= 4; x++){
    for(int y = 1; y <= 4; y++){
      printf("f(%d, %d) = %d\n", x, y, fun(x, y));
    }
  }
}