From 060d43dbcfddfb806f79a01b3ad25d600065648e Mon Sep 17 00:00:00 2001 From: AZEN-SGG Date: Sun, 3 Nov 2024 11:46:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=201=D0=B5?= =?UTF-8?q?=20=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=91=D0=B8=D1=82=D0=BE=D0=B2=D1=8B=D0=BC=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BitwiseOperations/1Ex/main.c | 24 ++++++++++++++++++++++++ BitwiseOperations/1Ex/makefile | 8 ++++++++ BitwiseOperations/1Ex/pow.c | 13 +++++++++++++ BitwiseOperations/1Ex/pow.h | 6 ++++++ 4 files changed, 51 insertions(+) create mode 100644 BitwiseOperations/1Ex/main.c create mode 100644 BitwiseOperations/1Ex/makefile create mode 100644 BitwiseOperations/1Ex/pow.c create mode 100644 BitwiseOperations/1Ex/pow.h diff --git a/BitwiseOperations/1Ex/main.c b/BitwiseOperations/1Ex/main.c new file mode 100644 index 0000000..6e72b53 --- /dev/null +++ b/BitwiseOperations/1Ex/main.c @@ -0,0 +1,24 @@ +#include +#include "pow.h" + +#define IOE "InputError!\n" + +int main(void) { + double number; + int power; + + printf("Enter your number: "); + if (scanf("%lf", &number) == 0) { + printf("%s", IOE); + return -1; + } + + printf("Enter the power: "); + if (scanf("%d", &power) == 0) { + printf("%s", IOE); + return -2; + } + + printf("The number %.1lf to the power of %d is %.1lf\n", number, power, bitwisePow(number, power)); + return 0; +} diff --git a/BitwiseOperations/1Ex/makefile b/BitwiseOperations/1Ex/makefile new file mode 100644 index 0000000..ba659bf --- /dev/null +++ b/BitwiseOperations/1Ex/makefile @@ -0,0 +1,8 @@ +all: main.o pow.o + gcc main.o pow.o && del *.o + +main.o: main.c + gcc -c main.c + +pow.o: pow.c + gcc -c pow.c diff --git a/BitwiseOperations/1Ex/pow.c b/BitwiseOperations/1Ex/pow.c new file mode 100644 index 0000000..f9d7a5c --- /dev/null +++ b/BitwiseOperations/1Ex/pow.c @@ -0,0 +1,13 @@ +#include "pow.h" + +double bitwisePow(double number, int exponent) { + double result = 1; + + while (exponent != 0) { + if (exponent & 1) result *= number; + number *= number; + exponent >>= 1; + } + + return result; +} diff --git a/BitwiseOperations/1Ex/pow.h b/BitwiseOperations/1Ex/pow.h new file mode 100644 index 0000000..4034f26 --- /dev/null +++ b/BitwiseOperations/1Ex/pow.h @@ -0,0 +1,6 @@ +#ifndef POW +#define POW + +double bitwisePow(double number, int exponent); + +#endif