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.
// умножаем % за 1 месяц на весь срок депозита и записываем в profit
profit*=amountMonth;
cout<<profit<<" $"<<endl;
cout<<"Общая сумма выплаты в конце срока: "
<<sumDeposit+profit<<" $";
cout<<endl<<endl;
return0;
}
Result:
Perhaps you have any questions about the solution of tasks – ask them in the comments!
4.4
49
156 thoughts on “Tasks: arithmetic operations in C ++”
#include
using namespace std;
int main() { setlocale(LC_ALL,”RUS”); int a; cout<<"Введите четырехзначное число,I type to you in reverse order: "<>a; if(a>=1000&& a<=9999) { int first= a; int second = (a/10)%10; int third = (a/100)%10; int fourth = (a/1000)%10;
cout<<"А это тоже число только в обратном порядке: "<<first<<second<<third<<fourth<<endl;
} else{ cout<<"Вы ввели не четырехзначное число,перезапустите программу и попробуйте еще раз.\n"; } return 0;
you checked your code?? in line cout<<"Введите четырехзначное число,I type to you in reverse order: "a; at the end put the normal direction of the output to the screen and made variable and (removing from its pre cout) separate line cin >>a; then all zarabotatet
I quickly wrote it in pure C #include int main(void) { int sum, term, years, mount, a; float procent, result; do//loop to select continuation or exit { printf(“Enter sum contribution\n”); scanf_s(“%d”, &sum); printf(“Enter term contribution\n”); scanf_s(“%d”, &term); printf(“Enter interest rate\n”); scanf_s(“%f”, &percent); printf(“Enter nummber of days in year\nEnter nummber of days in mount\n”); scanf_s(“%d”, &years); scanf_s(“%d”, &mount); //We carry out the calculation using the formula and write the result to the result variable result = sum*(percent / 100) / years*mount; printf(“Procent per month is %.2f\n”, result); printf(“Per year is %.2f\n”, result * 12); printf(“Total is %.2f\n”, sum + (result * 12)); printf(“Enter 1 for continue or 0 for exit\n”); scanf_s(“%d”, &a); } while (a != 0);//end of cycle return 0; }
#include using namespace std; int main() { setlocale(LC_ALL, “RUS”); int num, bur, as, ad, of; num = 5678; as = 567; ad = 56; of = 5; bur = 10; num %= bur; cout << on one; as %= bur; cout << as; ad %= bur; cout << ad; of %= cage; cout << of << endl << endl << endl; }
//1 задачка которая запрашивает любое целое неотрицательное число у пользователя и выводит его реверс #include #include using namespace std;
int main() { setlocale(LC_ALL, “ru”); cout <> a) { int c; vector pres; vector res; if (a <= 9) cout << a; else { pres.push_back(a); int i = 0; while (true) { c = pres[i] % 10; res.push_back(c); pres.push_back((pres[i] – c) / 10); if (pres[i + 1] <= 9) { res.push_back(pres[i + 1]); break; } i ; }
cout << endl << "результат реверса числа :";
for (const int &el : res) { cout << el; } cout << endl << endl; } cout << "введите ваше неотрицательное целое число :"; } }
#include
using namespace std;
int main()
{
setlocale(LC_ALL,”RUS”);
int a;
cout<<"Введите четырехзначное число,I type to you in reverse order: "<>a;
if(a>=1000&& a<=9999)
{
int first= a;
int second = (a/10)%10;
int third = (a/100)%10;
int fourth = (a/1000)%10;
cout<<"А это тоже число только в обратном порядке: "<<first<<second<<third<<fourth<<endl;
}
else{
cout<<"Вы ввели не четырехзначное число,перезапустите программу и попробуйте еще раз.\n";
}
return 0;
you checked your code?? in line
cout<<"Введите четырехзначное число,I type to you in reverse order: "a;
at the end put the normal direction of the output to the screen and made variable and (removing from its pre cout) separate line cin >>a; then all zarabotatet
Kirill, he has everything written correctly. This site is distorted. Try copying your code and posting it in a comment.. You'll see
I spent so long fiddling with the second task simply because “annual interest ”
made it like int)))))))))))00
I quickly wrote it in pure C
#include
int main(void)
{
int sum, term, years, mount, a;
float procent, result;
do//loop to select continuation or exit
{
printf(“Enter sum contribution\n”);
scanf_s(“%d”, &sum);
printf(“Enter term contribution\n”);
scanf_s(“%d”, &term);
printf(“Enter interest rate\n”);
scanf_s(“%f”, &percent);
printf(“Enter nummber of days in year\nEnter nummber of days in mount\n”);
scanf_s(“%d”, &years);
scanf_s(“%d”, &mount);
//We carry out the calculation using the formula and write the result to the result variable
result = sum*(percent / 100) / years*mount;
printf(“Procent per month is %.2f\n”, result);
printf(“Per year is %.2f\n”, result * 12);
printf(“Total is %.2f\n”, sum + (result * 12));
printf(“Enter 1 for continue or 0 for exit\n”);
scanf_s(“%d”, &a);
} while (a != 0);//end of cycle
return 0;
}
#include
using namespace std;
int main()
{ setlocale(LC_ALL, “RUS”);
int num, bur, as, ad, of;
num = 5678;
as = 567;
ad = 56;
of = 5;
bur = 10;
num %= bur;
cout << on one;
as %= bur;
cout << as;
ad %= bur;
cout << ad;
of %= cage;
cout << of << endl << endl << endl;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
double item, sum, sux, dead;
int hour, DaysInYear , DaysInMounth ;
DaysInMounth = 30;
DaysInYear = 365;
pr_stavka = (double)5 / 100;
cout <<"Здравствуйте! Вас приветствует программа для рассчета процентной прибыли от вашего вклада в месяц."<<endl<< "Введите сумму вклада: " <> sum;
cout << "американских долларов" << endl;
sux = I am * pr_stavka / DaysInYear * DaysInMounth;
cout << "Введите срок хранения депозита в месяцах: " <> hour;
cout << "Прибыль с депозита в месяц: " << sux<<" долларов" << endl;
dead = sux * hour;
cout << "Прибыль за весь срок депозита: "<< dead << " долларов" << endl;
cout << "Общая сумма к выплате в конце срока: " << dead+sum << " долларов" << endl;
cout << "Спасибо что пользуетесь услугами нашего банка!" << endl;
cout << "Приходите ещё!";
cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
return 0;
}
#include
using namespace std;
int main()
{
float sum_depos, income;
int month;
const int percent = 5, day_in_year = 365, day_in_month = 30;
cout <> sum_depos;
cout <> month;
income = sum_depos * (percent / 100) / day_in_year * day_in_month;
cout << "Your income per month: " << income << endl;
income *= month;
cout << "Your income per all time" << income << endl;
cout << "Summ of pay: " << income + sum_depos;
return 0;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “RUS”);
int time;
float procent, money;
double mes=1;
cout <> money;
cout <> time;
cout <> percent;
mes=money*(percent/100)/365*30;
cout << " Profit from deposit for 1 month (values are approximate): " << my<<endl;
cout << " Прибыль от депозита за время хранения: " << mes*vremya << endl;
return 0;
}
//1 задачка которая запрашивает любое целое неотрицательное число у пользователя и выводит его реверс
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “ru”);
cout <> a)
{
int c;
vector pres;
vector res;
if (a <= 9)
cout << a;
else
{
pres.push_back(a);
int i = 0;
while (true)
{
c = pres[i] % 10;
res.push_back(c);
pres.push_back((pres[i] – c) / 10);
if (pres[i + 1] <= 9)
{
res.push_back(pres[i + 1]);
break;
}
i ;
}
cout << endl << "результат реверса числа :";
for (const int &el : res)
{
cout << el;
}
cout << endl << endl;
}
cout << "введите ваше неотрицательное целое число :";
}
}