1. Common task: Given the four-digit number (for example 5678), display the numbers in reverse order of which is the number of member. That is, we should see on the screen 8765. Tip: to take from among the individual numbers, should be applied to the modulo 10.
Show code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intmainNumber=5678;
cout<<"Дано целое число: "<<mainNumber<<endl;
cout<<"Число наизнанку: ";
// остаток от деления четырехзначного числа 5678 на 10
cout<<mainNumber%10;// 5678 % 10 = 8
// далее делим mainNumber на 10 и записываем в переменную
// так как тип переменной int, дробная часть отбросится
// и mainNumber будет равен 567 (а не 567,8)
mainNumber/=10;
// показываем остаток от деления 567 на 10 на экран
cout<<mainNumber%10;
mainNumber/=10;
cout<<mainNumber%10;
mainNumber/=10;
cout<<mainNumber%10;
mainNumber/=10;
cout<<endl<<endl;
return0;
}
Result:
2. The site of almost any commercial bank, you can find the so-called Deposit calculator, which allows people to, not wishing to go into the formula for calculating interest rates, to know how much they will receive. To do this, they just fill in certain fields, press the button and see the result. This is a simple program, which has already been able to write each one of you. So, a task: The user enters the amount of the deposit and the number of months of keeping money in the bank. It is necessary to calculate and show the screen profit from the deposit in a month, for the entire term of the deposit, and the total amount payable at the end of the period. Currency let it be – U.S. dollar. Interest rate – 5% APR. The formula for calculating percent per month– SumDeposit * (interest rate / 100) / daysperyear * dayspermonths.
# ez gg wp #include using namespace std; int main() { int a = 0; int b = 0; int c = 0; int d = 0; you e = 0; int f = 0; cout << "vvedite chetirehznachnoe chislo" <> a; while (a > 9999) { cout << "error" << endl; return 0; } while (a < 1000) { cout << "error" << endl; return 0; } b = a / 1000; b = b % 10; c = a / 100; c = c % 10; d = a / 10; d = d % 10; and = a; and = and % 10; cout << e << d << c << b; return 0; }
so as not to constantly suffer and not write through //cout << mainNumber % 10; mainNumber /= 10; //////////////several times, namely as many times as a significant number, and do this through the for//////////////////////////////// ///////after half an hour, the tormented doper himself///////////////// #include using namespace std;
int main() { setlocale(LC_ALL, “rus”);
int mainNumber = 56786895154; cout << "дано целое число:" << mainNumber << endl; cout << "число на изнанку:";
for (int i = 0; i < 11; i ) { cout << mainNumber % 10; mainNumber /= 10; }
#include #include using namespace std; int main() { setlocale(LC_ALL, “RUS”); int x; define PI(“Введите первое число: “); cin >> x; define PI(“Result: “); do { cout << x % 10; x /= 10; } while (x); }
#include
using namespace std;
int main(){
double dep, months, percent;
cout <> dep;
cout <> percent;
//cout ;
cout <> months;
cout << "Расчет" << endl;
cout << "===========================================================" << endl;
dep /= 100;
dep *= percent;
dep /= months;
cout << "Ежемесячные проценты: " << dep << " долларов" << endl;
dep *= months;
cout << "Общая сумма депозита за весь период: " << dep;
}
so you can do it by char
char a,b,c,d;
cin>>a>>b>>c>>d;
cout<<d<<c<<b<<a;
I'm talking about 1 the task
Horrible, commenting didn't convey all my code, in the end you will understand what is there…(
# ez gg wp
#include
using namespace std;
int main()
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
you e = 0;
int f = 0;
cout << "vvedite chetirehznachnoe chislo" <> a;
while (a > 9999) {
cout << "error" << endl;
return 0;
}
while (a < 1000) {
cout << "error" << endl;
return 0;
}
b = a / 1000;
b = b % 10;
c = a / 100;
c = c % 10;
d = a / 10;
d = d % 10;
and = a;
and = and % 10;
cout << e << d << c << b;
return 0;
}
so as not to constantly suffer and not write through
//cout << mainNumber % 10;
mainNumber /= 10; //////////////several times, namely as many times as a significant number, and do this through the for////////////////////////////////
///////after half an hour, the tormented doper himself/////////////////
#include
using namespace std;
int main() {
setlocale(LC_ALL, “rus”);
int mainNumber = 56786895154;
cout << "дано целое число:" << mainNumber << endl;
cout << "число на изнанку:";
for (int i = 0; i < 11; i ) {
cout << mainNumber % 10;
mainNumber /= 10;
}
cout << endl << endl;
return 0;
}
//You can still improve this way after half an hour it came to mind again ))))
#include
using namespace std;
int main() {
setlocale(LC_ALL, “rus”);
int Number; // variable to store how many digits you enter
int MainNumber;
cout <> MainNumber;
cout <> Number;
cout << "число на изнанку: ";
for (int i = 1; i < Number; i ) {
cout << MainNumber % 10;
MainNumber /= 10;
}
cout << MainNumber;
cout << endl << endl;
return 0;
}
// at the top case an erroneous code
#include
using namespace std;
int main() {
setlocale(LC_ALL, “rus”);
int Number; //variable to store how many digits you enter
int MainNumber;
cout <> MainNumber;
cout <> Number;
cout << "число на изнанку: ";
for (int i = 1; i < Number; i ) {
cout << MainNumber % 10;
MainNumber /= 10;
}
cout << MainNumber;
cout << endl << endl;
return 0;
}
To not take a steam bath with unnecessary variables. You can loop for any significant number
do {
cout << MainNumber % 10;
MainNumber /= 10;
} while (MainNumber);
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “RUS”);
short int x;
define PI(“Введите первое число: “);
cin >> x;
define PI(“Result: %d%d%d%d”, x % 10, (x / 10) % 10, (x / 100) % 10, (x / 1000) % 10);
}
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “RUS”);
int x;
define PI(“Введите первое число: “);
cin >> x;
define PI(“Result: “);
do
{
cout << x % 10;
x /= 10;
} while (x);
}
#include
#include
using namespace std;
#define CC cout << "Bug" <> dep;
define PI(“Введите количество месяцев: “);
cin >> mou;
define PI(“Enter interest rate: “);
cin >> protcent;
prOneMou = dep * (protcent / 100.0) / 365.0 * 30.0;
define PI(“\n\n—————- Calculation —————-\nn%d * (%d / 100) / 365 * 30 = %d Rub nInterest for the entire term: %d RubnTotal you will get: %d Rubn”, dep, protcent, prOneMou, prOneMou * mou, (prOneMou*mou)+dep);
define PI(“It will work out in a month(from percent): %d Rubnn—————- At compound interest —————-\n”, prOneMou);
for (int i = 1; i <= mou; i )
{
prOneMou = dep * (protcent / 100.0) / 365.0 * 30.0;
dep += prOneMou;
}
define PI("Итого получите: %d Rub\n", dep);
}
#include
using namespace std;
//First task
int main()
{
int a;
cin >> a;
while (a != 0) {
cout << a % 10;
a /= 10;
}
return 0;
}
I did that
#include
#include
#include
using namespace std;
int main() {
setlocale(0, “”);
int x;
bot:
cout << "-Сколько символов будет в вашем числе?" <> x;
int nums;
cout << "-Ведите число а мы сделаем его на изнанку: " <> nums;
for (int a = 0; a < x – 1; a++) {
cout << nums % 10;
numbers /= 10;
}
cout << nums;
return 0;
}