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!

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

  1. I think it's more accurate:
    #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);

    float a, b;
    float mes1 = 0;
    float god1 = 0;
    float sum = 0;
    cout <> a;
    cout <> b;
    cout << "Проценты в месяц: ";
    mes1 = a*5/100/12;
    cout << mes1 << endl;
    cout << "Проценты в год: ";
    god1 = mes1 * 12;
    cout << good1 << endl;
    cout << "Общая сумма процентов: ";
    mes1 = mes1 * 12 * b;
    cout << mes1 << endl;
    cout << "Общая сумма выплаты: ";
    sum = a + b * good1;
    cout << sum << endl;

    cout << endl;
    return 0;
    }

  2. #include
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);

    float a = 0;
    // ” ‘ a ‘ – deposit amount ”
    float b = 0;
    // ” ‘ b ‘ – number of months of keeping money in the bank”
    float c = 0.05;
    // ” ‘ c ‘ – interest rate 5 %”
    float d = 365;
    // ” ‘ d ‘ – number of days per year set as a constant number”
    float e = 31;
    // ” ‘ e ‘ – the number of days in a month is set as a constant number”

    cout << "Deposit amount" <> a;

    cout << "Months" <> b;

    cout << "Profit per month" << " " << a * c / d * e << endl;

    cout << "All term profit" << " " << a *c / d * e * b << endl;

    cout << "Total amount payable after term" << " " << a + (a *c / d * e *b) << endl;

    return 0;
    }

  3. int main(){
    setlocale(LC_ALL, “RUS”);

    int k;
    cout <> k;

    while (k!=0){
    cout << k % 10;
    k = k / 10;
    }
    cout << endl;

    system("pause");

    return 0;
    }

  4. A little off task, but thought so:

    int main(){
    setlocale(LC_ALL, “RUS”);
    float sum, profit, annual = 0.05;
    int monthInYear = 12, amountMonth;
    cout <> sum;
    cout <> amountMonth;
    cout << endl << "Сумма: " << sum + (amountMonth*(sum*annual)/monthInYear) << " rub" << endl;
    system("pause");
    return 0;
    }

  5. #include ;
    #include ;
    #include ;
    using namespace std;

    int main()
    {
    setlocale(LC_ALL, “rus”);
    int sum_of_dep = 0;
    int deposit_term = 0;
    short day_start = 0;
    short month_start = 0;
    int year_start = 0;
    short day_end = 0;
    short month_end = 0;
    int year_end = 0;
    int sum_of_procent = 0;
    int day_in_month = 30;
    float deposit_rate = 5;
    int year_duration = 360;

    cout << "Введите сумму депозита: " <> sum_of_dep;

    cout << "Укажите дату оформления депозита(day month Year): " << endl;
    cout << "День: " <> day_start;
    cout << "Месяц: " <> month_start;
    cout << "Год: " <> year_start;

    if (year_start>9999 || year_start12 || month_start31 || day_start 28)
    cout << "Некоректная дата" << endl;

    cout << endl;

    cout << "Укажите дату окончания депозита(day month Year): " << endl;
    cout << "День: " <> day_end;
    cout << "Месяц: " <> month_end;
    cout << "Год: " <> year_end;

    if (year_end>9999 || year_end12 || month_end31 || day_end 28)
    cout << "Некоректная дата" << endl;

    cout << endl;
    // calculating the difference between days using the Julian day calculation
    float a1, m1, a2, m2;
    int a4 = 12; // variable in the formula for calculating the Julian day
    int y1, y2, sb1, jdn2;

    a1 = (14 – month_start) / a4;
    y1 = year_start + 4800 – A1;
    m1 = (month_start + (12 * A1)) – 3;

    jdn1 = day_start + ((153 * m1 + 2) / 5) + 365 * y1 + (y1 / 4) – (y1 / 100) + (y1 / 400) – 32045;

    a2 = (14 – month_end)/a4;
    y2 = year_end + 4800 – a2;
    m2 = (month_end + (12 * a2)) – 3;
    jdn2 = day_end + ((153 * m2 + 2) / 5) + 365 * y2 + (y2 / 4) – (y2 / 100) + (y2 / 400) – 32045;

    deposit_term = jdn2 – sb1;
    cout << "Срок депозита = " << deposit_term << endl;

    //daily interest calculation. annual rate 5%.
    //daily interest rate calculation:

    float procent_on_day;
    procent_on_day = (deposit_rate / year_duration) * 10;
    double a = procent_on_day; //rounding to hundredths
    double b = a*1000.0;
    int tmp = b + 0.5;
    b = (double)tmp / 1000.0;
    procent_on_day = b;
    cout << "Процентная ставка – 5% APR" << endl;

    //monthly interest (the basic average number of days in a month is 30)
    float procent_on_month;
    procent_on_month = procent_on_day * 30;
    //Profit on deposit per month
    float profit_on_month;
    profit_on_month = (procent_on_month * sum_of_dep) / 100;
    //Profit on deposit for the entire term
    float profit_on_all_term;
    profit_on_all_term = (procent_on_day * deposit_term) * sum_of_dep / 100;
    double x = profit_on_all_term; //rounding to hundredths
    double y = x*100.0;
    int tmp2 = y + 0.5;
    y = (double)tmp2 / 100.0;
    profit_on_all_term = y;

    cout << "Процентов начислено за месяц: " << procent_on_month << endl;
    cout << "Прибыль по депозиту за месяц: " << profit_on_month << endl;
    cout << "Прибыль по депозиту за весь срок:" << profit_on_all_term << endl;

    system("pause");
    return 0;
    }

  6. #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, “RUS”);
    int sum = 0;
    int term = 0;
    float sum1 = 0;
    cout <> sum;
    cout <> srok;
    sum1 = sum + sum * srok * 5 / 36500;
    cout << "\n\n Поздравляем! The amount of your deposit with interest through " << srok << " months will be: " << sum1 << " Bucks :-)\nnn Our bank wishes you good luck and good mood!!!\n\n\n\n\n\n\n\n\n";
    setlocale (LC_ALL, "RUS");
    // std::cout << "Hello World!\n";
    return 0;
    }

  7. #include
    using namespace std;

    int main()
    {

    int m = 5678;

    cout << m<< endl;
    for (int i=0;i<3;i )
    {
    cout<< m;
    m/=10;

    }

    cout << m<< endl;
    }

Leave a Reply

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