The basics of programming in c++ for beginners

Tasks: arithmetic operations in C ++

If you have already read the articleArithmetic operations in C ++ you can begin to practice.

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.

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.

Perhaps you have any questions about the solution of tasks – ask them in the comments!

156 thoughts on “Tasks: arithmetic operations in C ++

  1. The first task is done easily using a loop:

    #include
    using namespace std;
    int main ()
    {
    setlocale(LC_ALL, "Russian");
    cout << a;
    for (int i = 0; i < 4; i++)
    {
    cout << a % 10;
    a /= 10;
    }
    cout << endl;
    system("pause");
    return 0;
    }

    1. #include

      using namespace std;
      int main ()
      {
      int a;
      setlocale(LC_ALL, “Russian”);
      cin>> a;
      for (int i = 0; i < 4; i )
      {
      cout << a % 10;
      a /= 10;
      }
      cout << endl;
      system("pause");
      return 0;
      }

  2. I slightly modified the code for problem #1…we don't just need one at a time, display the digits of a number on the back of the screen, and turn the number over so that you can continue to use it…if I understand correctly of course.

  3. My solution to the challenge


    #include
    #include
    #define line cout << "---------------------------------------" << endl
    #define taskcls system("cls");

    using namespace std;

    int main()
    {
    setlocale(0, "russian");

    /* 1 задача */
    cout << "1 задача" << endl;
    int enteredNumber;
    cout << enteredNumber; // вводим число
    if(enteredNumber >= 10000) // проверка числа на четырехзначность
    {
    cout << "Введенное значение не является четырехзначным!\n";
    cout << enteredNumber;
    }
    int temp1, temp2, temp3, temp4;
    temp1 = enteredNumber % 10;
    temp2 = enteredNumber / 10 % 10;
    temp3 = enteredNumber / 100 % 10;
    temp4 = enteredNumber / 1000 % 10;

    cout << "Число в обратно порядке: " << temp1 << temp2 << temp3 << temp4;
    cout << endl;
    system("pause");
    taskcls;

    /* 2 задача */
    cout << "2 задача" << endl;
    double deposit, profit;
    int months;
    cout << deposit;
    taskcls;
    cout << months;
    taskcls;
    profit = deposit * (5.0 / 100.0) / 365.0 * 30.0;
    cout << "Прибыль в месяц, при депозите в " << deposit << " USD составит: " << profit << " USD\n";
    profit *= months; // проценты
    line;
    cout << "Проценты: " << profit << endl;
    line;
    cout << "Общая прибыль: " << deposit + profit;

    _getch();
    return 0;
    }

  4. #include
    using namespace std;

    int main()
    { setlocale(0, "");
    double sum_depozita = 0;
    double month = 0;
    const double prozent_stavk = 7;
    const double day_in_gody = 365;
    double day_in_month;
    cout << sum_depozita;
    cout << month;
    cout << day_in_month;
    double deneg_in_month = sum_depozita * (prozent_stavk / 100) / day_in_gody * day_in_month;
    cout <<"Денег в месяц: " << deneg_in_month << endl;
    double deneg_vsego = deneg_in_month * month;
    cout <<"Всего за все месяцы денег: " << deneg_vsego << endl;
    return 0;
    }

  5. Crap, you can delete the first comment.
    I don’t know why or how it should be, but your code believes that if the investment amount 100$, and the percentage per year 100% and deadline 12 there will be a profit 98$.
    I did it, look I get it right!

  6. #include
    using namespace std;
    int main()
    {
    int sum, a, b, c, e;

    cout <> sum ;

    a = sum / 1000;
    b = (sum – a * 1000 )/ 100;
    c = (sum – a * 1000 – b * 100 ) / 10;
    e = (sum – a * 1000 – b * 100 – c * 10 ) / 1;

    cout << e << c << b << a << endl;
    return 0;
    }

  7. К сожалению, I do not know, how to add code to a special form, how do you do, so I'll copy about. I'm just taking my first steps in programming., I chose C++ as difficult, fundamental, and most importantly an interesting language. Hope, that the spark of interest will not go out due to difficulties, and I will learn to do something really useful.
    P.S. I have, by the way according to the data 1000 usd through 12 it turns out exactly months 1050. The rate is, annual, and the number of days in a year does not matter at all, at least, the conditions don't say that. I will be happy to hear any comments and suggestions regarding the listing..

    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    float sumOfDeposite;
    you termOfSave;
    cout << "Введите сумму, which you want to deposit, usd" <> sumOfDeposite;
    cout << "Введите срок депозита (months)" <> termOfSave;

    float profitPerMonth, allProfit, maxSum, depRate = 0.05;

    profitPerMonth = sumOfDeposite * depRate;
    profitPerMonth /= 12;
    cout << "Ваша прибыль: " << profitPerMonth << " usd per month " << endl;
    allProfit = profitPerMonth * termOfSave;
    cout << "Прибыль за весь срок действия депозита: " << allProfit << " usd " << endl;
    maxSum = sumOfDeposit + allProfit;
    cout << "Общая сумма через " << termOfSave << " months(a): " << maxSum << " usd " << endl;

    system ("pause");
    return 0;
    }

  8. it seems easier this way :D
    #include
    using namespace std;

    int main(){

    long long int number = 0;

    cout <> number; // enter the number

    do{
    cout << number % 10 << " ";
    number = number / 10;
    } while (number % 10 != 0);

    system("pause");

    return 0;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *