add src-space c/cpp
This commit is contained in:
@@ -1 +1,15 @@
|
|||||||
CC =
|
CC = gcc
|
||||||
|
|
||||||
|
SRC_DIR = ./src
|
||||||
|
|
||||||
|
TARGET = main.c
|
||||||
|
|
||||||
|
BUILD_DIR = ../../build
|
||||||
|
|
||||||
|
OUTPUT = c.out
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(CC) -o $(BUILD_DIR)/$(OUTPUT) -O2 -Wall -lm --std=c11 -fsanitize=address,leak,undefined $(SRC_DIR)/$(TARGET)
|
||||||
|
|
||||||
|
run: build
|
||||||
|
$(BUILD_DIR)/$(OUTPUT)
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ int fib(int n) {
|
|||||||
int main() {
|
int main() {
|
||||||
int temp;
|
int temp;
|
||||||
scanf("%d", &temp);
|
scanf("%d", &temp);
|
||||||
printf("%d", fib(temp));
|
printf("%d\n", fib(temp));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
15
space/src-cpp/Makefile
Normal file
15
space/src-cpp/Makefile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CC = g++
|
||||||
|
|
||||||
|
SRC_DIR = ./src
|
||||||
|
|
||||||
|
TARGET = main.cpp
|
||||||
|
|
||||||
|
BUILD_DIR = ../../build
|
||||||
|
|
||||||
|
OUTPUT = cpp.out
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(CC) -o $(BUILD_DIR)/$(OUTPUT) -O2 -Wall -lm --std=c++17 -fsanitize=address,leak,undefined $(SRC_DIR)/$(TARGET)
|
||||||
|
|
||||||
|
run: build
|
||||||
|
$(BUILD_DIR)/$(OUTPUT)
|
||||||
17
space/src-cpp/src/main.cpp
Normal file
17
space/src-cpp/src/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int fib(int n) {
|
||||||
|
if (n == 0 || n == 1) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
return fib(n - 1) + fib(n - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int temp;
|
||||||
|
std::cin >> temp;
|
||||||
|
|
||||||
|
std::cout << fib(temp) << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user