roberthsu2003 / cAndC-

48 stars 18 forks source link

c++ 1_3_5_作業上,請使用macro,完成以下的程式 #20

Closed roberthsu2003 closed 9 months ago

roberthsu2003 commented 10 months ago
#include <iostream>
#define 請依照下列程式碼!定義出正確的macro
int main() {
    int s, result;
    cout << "請輸入數字:";
    cin >> s;
    result = SQUARE(s);
    cout << s << "的平方為:" << result << endl;
        result = SQUARE(s+1);
       cout << s+1 << "的平方為:" << result << endl;
Lancehsu1030 commented 10 months ago

define SQUARE(x) (x) * (x)``

FangYu0113 commented 10 months ago
#include <iostream>
#define SQUARE(x) (x)*(x)
using namespace std;
int main()
{
    int s, result;
    cout << "請輸入數字:";
    cin >> s;
    result = SQUARE(s);
    cout << s << "的平方為:" << result << endl;
    result = SQUARE(s+1);
    cout << s+1 << "的平方為:" << result << endl;
}
AmaoTaiwan commented 10 months ago
#include <iostream>
#include <math.h>
#define SQUARE(x) pow((x),2)
using namespace std;
int main()
{
    int s, result;
    cout << "請輸入數字:";
    cin >> s;
    result = SQUARE(s);
    cout << s << "的平方為:" << result << endl;
    result = SQUARE(s+1);
    cout << s+1 << "的平方為:" << result << endl;
}
a3137418 commented 10 months ago
#include <iostream>
#define SQUARE(x) (x) * (x)

using namespace std;

int main() {
  int s, result;
  cout << "請輸入數字:";
  cin >> s;
  result = SQUARE(s);
  cout << s << "的平方為:" << result << endl;
        result = SQUARE(s+1);
       cout << s+1 << "的平方為:" << result << endl;
}