22 февраля 2016 г.

Определить, является ли введённое число любой разрядности палиндромом (например, 1234321 – палиндром, 12345 – не палиндром).

int digit;
cout << "Enter digit:";
cin >> digit;

int old_digit = digit;
int new_digit = 0;
while (digit > 0)
{
int tmp = digit % 10;
new_digit = new_digit * 10 + tmp;
digit = digit / 10;
}
if (new_digit == old_digit)
cout << "palindrom" << endl;
else
cout << "No palindrom" << endl;
system("pause");

Написать программу, которая выводят на экран ромб (пользователь вводит диагональ), состоящий из символа '*'.

int digit;

cout << "Enter digit: ";
cin >> digit;
cout << "\n";
digit /= 2;
digit++;

for (int i = 0; i<digit * 2 - 1; i++)
{
for (int y = 0; y<digit * 2 - 1; y++)
{
if (y >= digit - i - 1 && y <= digit - 1 + i&&i<digit + y&&y<digit * 3 - i - 2)
{
cout << "*";
continue;
}
cout << " ";
}
cout << "\n";
}
system("pause");

Написать программу, которая выводят на экран ромб (пользователь вводит диагональ), состоящий из символа '*'. Фигура внутри пустая.

int digit;

cout << "Enter digit: ";
cin >> digit;
cout << "\n";


for (int i = 0; i<digit; i++)
{
for (int j = 0; j<digit; j++)
{
if ( j == digit / 2 + i || j == digit / 2 - i || j == i - digit / 2 || j==digit-i+digit/2-1)
cout << "*";
else
cout << " ";
}
cout << endl;
}
system("pause");

Написать программу, которая выводит на экран елочку.

srand(time(0));
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);

int length_of_sections, summ_sections;
cout << "Enter summ sections:";
cin >> summ_sections;
do
{
cout << "Enter length of sections(only even digit):";
cin >> length_of_sections;
} while (length_of_sections % 2 == 0);

int front=0;

for (int i = 1; i <= summ_sections; i++)
{
front++;
if (front == 15)
front = 1;

for (int i = 0; i<length_of_sections / 2 + 1; i++)
{
for (int j = 0; j<length_of_sections; j++)
{
if (j <= length_of_sections / 2 + i &&j >= length_of_sections / 2 - i)
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | front));
cout << "*";
}
else
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | front));
cout << " ";
}
}
cout << "\n";
}
}
system("pause");

Тоже самое, но фигура перевернута и пустая внутри.

HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
int length_of_sections, summ_sections;
cout << "Enter summ sections:";
cin >> summ_sections;
do
{
cout << "Enter length of sections(only even digit):";
cin >> length_of_sections;
} while (length_of_sections % 2 == 0);

int front=0;

for (int i = 1; i <= summ_sections; i++)
{
front++;
if (front == 15)
front = 1;

for (int i = 0; i<length_of_sections / 2 + 1; i++)
{
for (int j = 0; j < length_of_sections; j++)
{
if (i == 0 || j == i || j == length_of_sections - i - 1)
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | front));
cout << "*";
}
else
cout << " ";
}
cout <<endl;
}
}
system("pause");

Написать программу, которая выводит на экран все "счастливые" номера трамвайных билетов и подсчитывает их общее количество.

for (int digit = 100000; digit <= 999999; digit++)
{
int first = 0;
int second = 0;
int tmp = digit;
while (tmp > 0)
{
if (tmp < 1000)
first += tmp % 10;
else
second += tmp % 10;
tmp /= 10;
}
if (first == second)
cout << digit << endl;
}
system("pause");

Нарисовать звездочками флаг Великобритании.

HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
int digit;
do
{
cout << "Enter digit(only even digit):";
cin >> digit;
} while (digit % 2 == 0);

cout << endl;

for (int i = 0; i < digit; i++)
{
for (int j = 0; j < digit; j++)
{
if (j == i || j == digit - i-1||i==digit/2||j==digit/2)
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | RED));
cout << char(219);

}
else if (i == digit / 2 - 1 || j == digit / 2 - 1 || i == digit / 2 + 1 || j == digit / 2 + 1||
j == i-1 || j == digit - i - 2|| j == i+1 || j == digit - i)
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | WHITE));
cout << char(219);
}
else
{
SetConsoleTextAttribute(h, (WORD)(BLACK << 4 | BLUE));
cout << char(219);
}

}
cout << endl;
}
cout << endl;
system("pause");