Skip to content

Instantly share code, notes, and snippets.

@Allespro
Last active March 12, 2019 17:32
Show Gist options
  • Save Allespro/f45991b228dd10a507974849394cd6d2 to your computer and use it in GitHub Desktop.
Save Allespro/f45991b228dd10a507974849394cd6d2 to your computer and use it in GitHub Desktop.
My C++ homework.....
#include <iostream>
using namespace std;
int nom1()
{
int number;
cin >> number;
cout << "Десятков: " << number / 10 << "\nЕдениц: " << number % 10 << "\nСумма цифр: " << (number / 10)+(number % 10) << endl;
return 1;
}
int nom2()
{
int number;
cin >> number;
int endnumber = ((number % 10)*10)+(number / 10);
cout << "Конечное число: " << endnumber << endl;
return 2;
}
int nom3()
{
int number;
cin >> number;
int array[3];
for (int i=0; i < 3; i++)
{
array[i] = number%10;
number /= 10;
}
cout << "Перевёрнутое число: ";
for (int i=0; i < 3; i++)
{
cout << array[i];
}
cout << endl;
return 3;
}
int nom4()
{
int a, b, swap;
cin >> a >> b;
swap = a;
a = b;
b = swap;
cout << "Обмен значениями:\n" << "a = " << a << "\nb = " << b << endl;
return 4;
}
int nom5()
{
/*
* Минута = 60 секунд
* Час = 3600 секунд
*/
int sec, hour = 0, min = 0, swapsec;
cin >> sec;
swapsec = sec;
while(swapsec > 3600)
{
swapsec -= 3600;
hour++;
}
cout << hour << " ";
swapsec = sec - hour * 3600;
while(swapsec > 60)
{
swapsec -= 60;
min++;
}
cout << min << " " << swapsec << endl;
return 5;
}
int nom6()
{
int number, array[4];
cin >> number;
for (int i=0; i < 4; i++)
{
array[i] = number%10;
number /= 10;
}
//cout << array[0] << array[1] << array[2] << array[3];
if((array[0] == array[3])&&(array[1]==array[2]))
{
cout << 1 << endl;
}
else
{
cout << 2 << endl;
}
return 6;
}
int main(int argc, char **argv)
{
setlocale(LC_ALL,"Rus");
int choose;
cout << "Выберете номер задачи от 1 до 6" << endl;
cin >> choose;
cout << "Выбрана задача " << choose << endl;
switch(choose)
{
case 1:
nom1();
break;
case 2:
nom2();
break;
case 3:
nom3();
break;
case 4:
nom4();
break;
case 5:
nom5();
break;
case 6:
nom6();
break;
default:
cout << "Ошибка, такой задачи нет!" << endl;
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment