* Computer Science/C++

상대오차, 백분율차 구하기

soicem 2019. 9. 16. 12:53
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
27
28
29
30
31
32
33
#include <iostream>
 
using namespace std;
 
int main(){
    cout << "0: relative error | 1: 백분율차" << '\n';
 
    int choose;
    cin >> choose;
    if(choose == 0){ // relative error
        int N;
        cin >> N;
        while(N--){
            double trueV, getV;
            cin >> trueV >> getV;
            double error = trueV - getV;
            cout << (error / trueV) * 100 << '%' <<'\n';
        }
    } else if(choose == 1){ // 백분율
        int N;
        cin >> N;
        while(N--){
            double v1, v2;
            cin >> v1 >> v2;
            double a;
            a = v1 - v2;
            if(a < 0) a = -a;
            cout << (a / ((v1 + v2) / 2)) * 100 << '%' << '\n';
        }
    }
    return 0;
}
 
 
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

'* Computer Science > C++' 카테고리의 다른 글

lower_bound / upper_bound  (0) 2021.05.30
2차원 vector rotate  (0) 2020.05.06
입력 길이 모를 때 string 공백 별로 입력  (0) 2019.08.23
cin 속도 향상  (0) 2019.08.22
hw13 meeting in pnu data structure class  (0) 2018.12.07