Skip to content

Commit bdbff44

Browse files
committed
local
1 parent d489c5d commit bdbff44

7 files changed

+138
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
int num;
7+
cin >> num;
8+
9+
// Is even using %2
10+
bool is_even1 = (num % 2 == 0);
11+
12+
// is even using /2
13+
double by2 = (double) num / 2.0;// this is either X.0 or X.5 (try 10, 11)
14+
by2 = by2 - (int) by2;// Remove X. This is now either 0 (for even) or 0.5 (for odd)
15+
bool is_even2 = by2 == 0;
16+
17+
// is even using %2
18+
int last_digit = num % 10; // even last digit is 0, 2, 4, 6, 8
19+
bool is_even3 = last_digit == 0 || last_digit == 2 || last_digit == 4 || last_digit == 6 || last_digit == 8;
20+
21+
return 0;
22+
}
23+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
double a1, a2, a3, a4, a5;
7+
cin >> a1 >> a2 >> a3 >> a4 >> a5;
8+
9+
double avg1 = (a1+a2+a3+a4+a5) / 5.0; // A
10+
double sum1 = (a1+a2+a3) / (a4+a5); // B
11+
double first3_avg = (a1+a2+a3) / 3.0;
12+
double last2_avg = (a4+a5) / 2.0;
13+
double avg2 = first3_avg / last2_avg; // C
14+
15+
cout<<avg1<<"\n";
16+
cout<<sum1<<"\n";
17+
cout<<avg2<<"\n";
18+
19+
cout<<sum1 * 2.0/3.0<<"\n"; // C = 2/3 B
20+
21+
return 0;
22+
}
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
int n;
7+
cin >> n;
8+
9+
int last1 = n % 10;
10+
n /= 10;
11+
12+
int last2 = n % 10;
13+
n /= 10;
14+
15+
int last3 = n % 10;
16+
n /= 10;
17+
18+
cout << last1 + last2 + last3 << "\n";
19+
20+
return 0;
21+
}
22+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
int n;
7+
cin >> n;
8+
9+
// /1000 => removes last 3 digits
10+
// %10 get next digit = 4th
11+
cout << (n / 1000) % 10 << "\n";
12+
13+
return 0;
14+
}
15+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
double a, b;
7+
cin>>a>>b;
8+
9+
double result = a/b;
10+
11+
cout<<result - (int)result;
12+
13+
return 0;
14+
}
15+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
int n, m;
7+
cin >> n >> m;
8+
9+
// let's try 13/5
10+
// 13/5 = 2 [2 complete units, each is 5]
11+
// 2*5 = 10 [total complete units]
12+
// Reminder is 13-10 = 3. This number generates the fractional part
13+
int result = n - (n / m) * m;
14+
15+
cout << result << " " << n % m << "\n";
16+
17+
return 0;
18+
}
19+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
6+
int n;
7+
cin >> n;
8+
9+
int is_even = n % 2 == 0;
10+
int is_odd = 1 - is_even;
11+
12+
// formula of 2 parts: only one of them will be activated
13+
int result = is_even * 100 + is_odd * 7;
14+
15+
cout<<result<<"\n";
16+
17+
18+
19+
return 0;
20+
}
21+

0 commit comments

Comments
 (0)