Created
September 26, 2018 14:04
-
-
Save kupp1/24c7d3bd262be9a29f92a8dfac413e6b to your computer and use it in GitHub Desktop.
UniLecs #122 Битовая Арифметика
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Задача: даны два числа K, N. Необходимо вычислить арифметическое выражение вида: | |
| K * 2^N, используя только битовые операции. | |
| Входные данные: K, N - натуральные числа, где K от 1 до 10^3, N от 1 до 20 | |
| Вывод: результат выражения K * 2^N | |
| Пример: K = 3, N = 4 | |
| Answer: 48 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char *argv[]) { | |
| if (argc < 2) | |
| return -1, puts("Enter K and N in command line as args"); | |
| int k = atoi(argv[1]); | |
| int n = atoi(argv[2]); | |
| k <<= n; | |
| printf("%d\n", k); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment