Skip to content

Instantly share code, notes, and snippets.

@fantom44ik
Created May 7, 2025 14:28
Show Gist options
  • Save fantom44ik/e9aa68cf75d4f92887d23d4b66afd42d to your computer and use it in GitHub Desktop.
Save fantom44ik/e9aa68cf75d4f92887d23d4b66afd42d to your computer and use it in GitHub Desktop.
#include <iostream>
#include <windows.h>
using namespace std;
void Line(int lenght, char symb, int color, bool horizontal) {
if (lenght < 0)
cout << "Error: Length cannot be negative!" << "\n";
else {
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h, color);
if (horizontal) {
for (int i = 0; i < lenght; i++) {
cout << symb;
}
}
else {
for (int i = 0; i < lenght; i++) {
cout << symb << "\n";
}
}
SetConsoleTextAttribute(h, 7);
}
}
void Rectangle(int width, int height, char border, char fill) {
if (width < 0 || height < 0)
cout << "Error; Width or height cannot be negative!" << "\n";
else {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (i == 0 || i == height - 1 || j == 0 || j == width - 1) {
cout << border;
}
else {
cout << fill;
}
}
cout << "\n";
}
}
}
void Cube_of_a_number(double number) {
if (number < 0)
cout << "Error: Number cannot be negative!" << "\n";
else {
double cube = number * number * number;
cout << "Result: " << cube << "\n";
}
}
void Prime_number(int num) {
if (num < 0)
cout << "Error: Number cannot be negative!" << "\n";
else {
bool isPrime = true;
for (int i = 2; i <= num / 2; i++) {
if (num % i == 0) {
isPrime = false;
}
}
if (isPrime && num > 1) {
cout << num << " is a prime number." << "\n";
}
else {
cout << num << " is not a prime number." << "\n";
}
}
}
int main()
{
//1st
Line(-20, '@', 12, true);
cout << "\n";
//2nd
Rectangle(15, 5, '#', '$');
cout << "\n";
//3rd
Cube_of_a_number(3);
cout << "\n";
//4th
Prime_number(4);
cout << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment