forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ceiling_Sum.cpp
56 lines (51 loc) · 1.12 KB
/
Ceiling_Sum.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<bits/stdc++.h>
using namespace std;
int largest(int arr[], int n)
{
int i;
// Initialize maximum element
int max = arr[0];
// Traverse array elements
// from second and compare
// every element with current max
for (i = 1; i < n; i++){
if (arr[i] > max){
max = arr[i];
}
}
return max;
}
int main() {
int T;
cin>>T;
int A,B,Z;
for(int i=0;i<T;i++){
cin>>A>>B;
Z=abs(B-A)+1;
int S[Z]={};
int a=0;
float f1;
float f2;
if(A<=B){
for(int j=A;j<=B;j++){
f1=float(B-j)/2;
f2=float(j-A)/2;
int X= ceil(f1)+ceil(f2);
S[a]=X;
a=a+1;
}
}
else{
for(int j=A;j>=B;j--){
f1=float(B-j)/2;
f2=float(j-A)/2;
int X= ceil(f1)+ceil(f2);
S[a]=X;
a=a+1;
}
}
int n = sizeof(S)/sizeof(S[0]);
cout<<largest(S,n)<<"\n";
}
return 0;
}