Сделал 1е Задание по Битовым операциям
This commit is contained in:
parent
baa0509a01
commit
060d43dbcf
4 changed files with 51 additions and 0 deletions
24
BitwiseOperations/1Ex/main.c
Normal file
24
BitwiseOperations/1Ex/main.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#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;
|
||||||
|
}
|
8
BitwiseOperations/1Ex/makefile
Normal file
8
BitwiseOperations/1Ex/makefile
Normal file
|
@ -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
|
13
BitwiseOperations/1Ex/pow.c
Normal file
13
BitwiseOperations/1Ex/pow.c
Normal file
|
@ -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;
|
||||||
|
}
|
6
BitwiseOperations/1Ex/pow.h
Normal file
6
BitwiseOperations/1Ex/pow.h
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef POW
|
||||||
|
#define POW
|
||||||
|
|
||||||
|
double bitwisePow(double number, int exponent);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue