Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- void prefix_vs_postfix() {
- int k = 5;
- std::cout << k << "\n";
- k++;
- std::cout << k << "\n";
- ++k;
- std::cout << k << "\n";
- double y = 1.5;
- y++;
- std::cout << y << "\n";
- // ++k - сначала k увеличится на 1, а затем присвоится в n
- int n = ++k;
- std::cout << "k:" << k << " n:" << n << "\n";
- k = 7;
- // ++k - сначала k присвоится в m, а затем увеличится на 1
- int m = k++;
- std::cout << "k:" << k << " m:" << m << "\n";
- k = 7;
- std::cout << "k++: " << k++ << "\n";
- std::cout << "k: " << k << "\n";
- k = 7;
- std::cout << "++k: " << ++k << "\n";
- std::cout << "k: " << k << "\n";
- int a = 5;
- std::cout << "a: " << a << "\n";
- std::cout << "a++ + (-a * ++a): " << a++ + (-a * ++a) << "\n";
- std::cout << "a: " << a << "\n";
- a = 5;
- std::cout << "a: " << a << "\n";
- std::cout << "++a + (-a * ++a): " << ++a + (-a * ++a) << "\n";
- std::cout << "a: " << a << "\n";
- }
- int counter = 0;
- long long factorial0(int n) {
- std::cout << "Start factorial " << counter << "\n";
- long long result = n;
- while (n > 2) {
- n--;
- result *= n;
- }
- counter++;
- return result;
- }
- long long factorial1(int n) {
- std::cout << "Start factorial " << counter << "\n";
- long long result = n;
- while (n > 2)
- result *= --n;
- counter++;
- return result;
- }
- void multy_tab() {
- int k = 0, n = 0;
- while (n <= 9) {
- k = 0;
- while (k <= 9) {
- std::cout << std::setw(2) << n * k++ << " ";
- }
- std::cout << "\n";
- n++;
- }
- }
- int main() {
- //prefix_vs_postfix();
- //std::cout << !5 << std::endl;
- /*std::cout << "2! = " << factorial0(2) << std::endl;
- std::cout << "5! = " << factorial1(5) << std::endl;
- std::cout << "4! = " << factorial0(4) << std::endl;
- std::cout << "3! = " << factorial0(3) << std::endl;
- std::cout << "6! = " << factorial1(6) << std::endl;
- */
- multy_tab();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement