diff options
Added yesterday's practice
1 files changed, 38 insertions, 0 deletions
| -rw-r--r-- | Year 1/Programming introduction/Practice-11.10.21.cpp | 38 |
diff --git a/Year 1/Programming introduction/Practice-11.10.21.cpp b/Year 1/Programming introduction/Practice-11.10.21.cpp new file mode 100644 index 0000000..370fc77 --- /dev/null +++ b/Year 1/Programming introduction/Practice-11.10.21.cpp @@ -0,0 +1,38 @@ +#include <iostream> + +using namespace std; + +void ex0() { + cout << (char)43; +} + +void ex1() { + int a; + cin >> a; + cout << a * (1 + a) / 2; // sum of arithmetic sequence, where a0 = 1 and d = 1 +} + +void ex2() { + int a; + cin >> a; + cout << ((a % 3 == 0) != (a % 5 == 0)); // != is logical XOR +} + +void ex3() { + int a; + cin >> a; + cout << a / 3 + a / 5 - (a / 5) / 3; +} + +void ex4() { + int a; + cin >> a; + a /= 3; + cout << (6 + (a - 1) * 3) * a / 2; // sum of arithmetic sequence, where a0 = 3 and d = 3 +} + +// Building and running in PowerShell: +// g++ .\*.cpp -o out.exe; if($?) { .\out.exe } +int main() { + ex4(); +} |
