roberthsu2003 / cAndC-

48 stars 18 forks source link

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

Closed roberthsu2003 closed 3 weeks ago

roberthsu2003 commented 2 months ago
截圖 2024-09-08 中午12 00 39
edward200897 commented 2 months 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 2 months 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));
    }
  }
}