Гавалян 515i

Run Settings
LanguageC
Language Version
Run Command
/* * @file main.c * @author Гавалян Д.Є, гр. 515і * @date 28 лютого 2025 * @brief Лабораторна робота № 1, варіант 19 * * Розгалуження та вибір. Завдання 3 */ #include <stdio.h> #include <locale.h> #include "module.h" int main() { setlocale(LC_ALL, ""); int N, room_count, balconies, floor, entrance; printf("Введіть номер квартири: "); if (scanf("%d", &N) !=1) { printf("Помилка: введене значення не є цiлочисельним.\n"); return 0; }; if (N <= 0 || N > 48) { printf("Некоректні дані! Спробуйте ввести ще раз!\n"); return 0; } get_place_information(N, &entrance, &floor); get_balcon_information(N, &room_count, &balconies); printf("Номер під'їзду: %d\n", entrance); printf("Номер поверху: %d\n", floor); printf("Кількість кімнат: %d\n", room_count); printf("Кількість балконів/лоджий: %d\n", balconies); return 0; }
/* * @file module.c * @author Гавалян Д.Є, гр. 515і * @date 28 лютого 2025 * @brief Лабораторна робота № 1, варіант 19 * * Розгалуження та вибір. Завдання 3 */ #include "module.h" void get_place_information(int N, int* entrance, int* floor) { int apartments_per_entrance = FLOORS * APARTMENTS_PER_FLOOR; *entrance = (N - 1) / apartments_per_entrance + 1; *floor = ((N - 1) % apartments_per_entrance) / APARTMENTS_PER_FLOOR + 1; } void get_balcon_information(int N, int* room_count, int* balconies) { int apartment_pos = (N - 1) % APARTMENTS_PER_FLOOR; if (apartment_pos == 0 || apartment_pos == 3) { *room_count = 2; *balconies = 1; } else if (apartment_pos == 1) { *room_count = 3; *balconies = 2; } else { *room_count = 1; *balconies = 1; } }
#ifndef MODULE_H #define MODULE_H #define FLOORS 12 #define ENTRANCES 3 #define APARTMENTS_PER_FLOOR 4 void get_place_information(int N, int* entrance, int* floor); void get_balcon_information(int N, int* room_count, int* balconies); #endif
Editor Settings
Theme
Key bindings
Full width
Lines