Problem Description

請依據下列說明求出該數學式的結果。    

The Input

輸入共 4 行:

第一行有兩個整數 a, b 請求出 a 的 b 次方的值。

第二行有一個整數,請求出該數字的平方根,精確到小數點下3位。

第三行有一個整數,請求出該數字的絕對值。

第四行有2個整數 a, b,請取一個整數亂數 x (a <= x < b)

所有的輸入整數及計算結果均不大於 231

The Output

根據每一行的輸入,輸出所要求的結果及格式。

Sample Input

2      10
25
-20
3      100

Sample Output

1024
5.000
20
RANDOM_NUMBER

-----* Problem from【ZeroJudge, an Online Judge System For Beginners

My Answer

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;
int main(void)
{
  srand(time(NULL));
  int a, b;
  while(cin>>a>>b){
    cout<<pow(a, float(b))<<endl;

    cin>>a;
    cout<<fixed<<setprecision(3)<<sqrt(a)<<endl;

    cin>>a;
    cout<<labs(a)<<endl;

    cin>>a>>b;
    int r;
    do{
      r=(rand()%(b-a+1))+a;
    }while(b==r);
    cout<<r<<endl; 
  }
  return 0;
}
 

 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(0) 人氣()