Compare commits
4 Commits
02d6e931f6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 92bfa117af | |||
| 280e806e82 | |||
| ce2208e668 | |||
| db5b04ed8f |
7
c-template/.github/copilot-instructions.md
vendored
Normal file
7
c-template/.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Workspace Instructions
|
||||||
|
|
||||||
|
- Keep the project compatible with C11 and CMake 3.16 or newer.
|
||||||
|
- Put public headers in `include/`, implementations in `src/`, and tests in `tests/`.
|
||||||
|
- Keep reusable functionality in libraries and link executables to those libraries.
|
||||||
|
- Register tests with CTest and avoid adding dependencies unless the project needs them.
|
||||||
|
- Verify changes with `cmake -S . -B build`, `cmake --build build`, and `ctest --test-dir build --output-on-failure`.
|
||||||
2
c-template/.gitignore
vendored
Normal file
2
c-template/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/build/
|
||||||
|
/cmake-build-*/
|
||||||
13
c-template/CMakeLists.txt
Normal file
13
c-template/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
|
project(c_template VERSION 1.0.0 LANGUAGES C)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
|
||||||
|
# add_library(greeting src/greeting.c)
|
||||||
|
# target_include_directories(greeting PUBLIC include)
|
||||||
|
# target_compile_features(greeting PUBLIC c_std_11)
|
||||||
|
|
||||||
|
add_executable(c_template src/main.c)
|
||||||
|
# target_link_libraries(c_template PRIVATE greeting)
|
||||||
|
|
||||||
31
c-template/README.md
Normal file
31
c-template/README.md
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Laba 6
|
||||||
|
|
||||||
|
Найти и удалить в заданной строке лишние пробелы между словами и
|
||||||
|
знаками препинания
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- CMake 3.16 or newer
|
||||||
|
- A C compiler with C11 support
|
||||||
|
|
||||||
|
## Configure and build
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cmake -S . -B build
|
||||||
|
cmake --build build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./build/c_template
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ctest --test-dir build --output-on-failure
|
||||||
|
```
|
||||||
|
|
||||||
|
The `greeting` library is an example of how to separate reusable code into a
|
||||||
|
public header and implementation. Replace it with your project's own modules.
|
||||||
7
c-template/src/main.c
Normal file
7
c-template/src/main.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
printf("Hello world");
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
10
c-template/tests/test_greeting.c
Normal file
10
c-template/tests/test_greeting.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "greeting.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
assert(strcmp(greeting_message(), "Hello, world!") == 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
2
lab-5/.gitignore
vendored
Normal file
2
lab-5/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/build/
|
||||||
|
/cmake-build-*/
|
||||||
6
lab-5/.vscode/extensions.json
vendored
Normal file
6
lab-5/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"ms-vscode.cpptools",
|
||||||
|
"ms-vscode.cmake-tools"
|
||||||
|
]
|
||||||
|
}
|
||||||
24
lab-5/.vscode/launch.json
vendored
Normal file
24
lab-5/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug CMake target",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${command:cmake.launchTargetPath}",
|
||||||
|
"cwd": "${command:cmake.launchTargetDirectory}",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerPath": "/usr/bin/gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
5
lab-5/.vscode/settings.json
vendored
Normal file
5
lab-5/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"cmake.useCMakePresets": "always",
|
||||||
|
"cmake.configureOnOpen": true,
|
||||||
|
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||||
|
}
|
||||||
23
lab-5/.vscode/tasks.json
vendored
Normal file
23
lab-5/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "CMake: build (Debug)",
|
||||||
|
"type": "cmake",
|
||||||
|
"command": "build",
|
||||||
|
"preset": "debug",
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": "$gcc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "CMake: build (Release)",
|
||||||
|
"type": "cmake",
|
||||||
|
"command": "build",
|
||||||
|
"preset": "release",
|
||||||
|
"problemMatcher": "$gcc"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
25
lab-5/CMakeLists.txt
Normal file
25
lab-5/CMakeLists.txt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
project(5laba_task6 VERSION 1.0.0 LANGUAGES C)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0 -Wall -Wextra -pedantic")
|
||||||
|
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||||
|
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
src/main.c
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
|
${CMAKE_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
# # Опционально: установка
|
||||||
|
# install(TARGETS ${PROJECT_NAME}
|
||||||
|
# RUNTIME DESTINATION bin
|
||||||
|
# )
|
||||||
33
lab-5/CMakePresets.json
Normal file
33
lab-5/CMakePresets.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"version": 3,
|
||||||
|
"configurePresets": [
|
||||||
|
{
|
||||||
|
"name": "debug",
|
||||||
|
"displayName": "Debug",
|
||||||
|
"generator": "Unix Makefiles",
|
||||||
|
"binaryDir": "${sourceDir}/build/debug",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Debug"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "release",
|
||||||
|
"displayName": "Release",
|
||||||
|
"generator": "Unix Makefiles",
|
||||||
|
"binaryDir": "${sourceDir}/build/release",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Release"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"buildPresets": [
|
||||||
|
{
|
||||||
|
"name": "debug",
|
||||||
|
"configurePreset": "debug"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "release",
|
||||||
|
"configurePreset": "release"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
32
lab-5/README.md
Normal file
32
lab-5/README.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Laba 5
|
||||||
|
|
||||||
|
Дано число n. Среди чисел 1, 2, …, n найти все те, которые можно
|
||||||
|
представить в виде суммы квадратов двух натуральных чисел. Для этого
|
||||||
|
определите функцию, позволяющую распознавать полные квадраты.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- CMake 3.16 or newer
|
||||||
|
- A C compiler with C11 support
|
||||||
|
|
||||||
|
## Configure and build
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cmake -S . -B build
|
||||||
|
cmake --build build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./build/c_template
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```sh
|
||||||
|
ctest --test-dir build --output-on-failure
|
||||||
|
```
|
||||||
|
|
||||||
|
The `greeting` library is an example of how to separate reusable code into a
|
||||||
|
public header and implementation. Replace it with your project's own modules.
|
||||||
34
lab-5/build.sh
Executable file
34
lab-5/build.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Build script for my_project
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Default build type
|
||||||
|
BUILD_TYPE="${1:-Debug}"
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Building my_project (${BUILD_TYPE})...${NC}"
|
||||||
|
|
||||||
|
# Create build directory if it doesn't exist
|
||||||
|
if [ ! -d "build" ]; then
|
||||||
|
echo -e "${YELLOW}Creating build directory...${NC}"
|
||||||
|
mkdir -p build
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd build
|
||||||
|
|
||||||
|
# Configure
|
||||||
|
echo -e "${YELLOW}Configuring CMake...${NC}"
|
||||||
|
cmake -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" ..
|
||||||
|
|
||||||
|
# Build
|
||||||
|
echo -e "${YELLOW}Compiling...${NC}"
|
||||||
|
make
|
||||||
|
|
||||||
|
echo -e "${GREEN}✓ Build completed successfully!${NC}"
|
||||||
7
lab-5/include/config.h
Normal file
7
lab-5/include/config.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef CONFIG_H
|
||||||
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#define PROJECT_NAME "my_project"
|
||||||
|
#define VERSION "1.0.0"
|
||||||
|
|
||||||
|
#endif /* CONFIG_H */
|
||||||
33
lab-5/src/main.c
Normal file
33
lab-5/src/main.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int issqr(int x) {
|
||||||
|
if (x < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i * i <= x; i++) {
|
||||||
|
if (i * i == x) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int n;
|
||||||
|
printf("Enter N: ");
|
||||||
|
scanf("%d", &n);
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++){
|
||||||
|
for (int a = 1; a*a < i; a++){
|
||||||
|
if (issqr(i-a*a)) {
|
||||||
|
printf("%d ", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user