The basics of programming in c++ for beginners

Tasks: while loops, do while, nested loops

We met with loops while and do while in C++ and c nested constructions in loops. Let us tasks solving.

1. Organize continuous input of numbers with the keyboard, until the user has entered 0. After entering a zero, show on the screen the number of numbers, which were introduced, their total amount and the arithmetic mean. Tip: you must declare the counter variable, that will count the number of entered numbers, and variable, that will accumulate a total sum of numbers.

2. It is necessary to sum up all the odd integers, which will introduce the user to the keyboard.

3. The task is more difficult. Draw an isosceles triangle of characters ^. The height of a user selects. For example: height = 5, on the screen

task nested loops

Read how to determine the mobile browser javascript.

123 thoughts on “Tasks: while loops, do while, nested loops

  1. Сделал через цикл for

    int main()
    int c=0; // переменная-счетчик количества введенных чисел
    int a; // переменная для ввода числа
    int b=0; // переменная-счетчик суммы введенных чисел
    for (int i = 0; ;i )
    cout << "Enter number" <> a;
    c = i;
    b += a;

    if (a == 0) // условие выхода из цикла
    cout << "number of entered numbers "<< c << endl; // выводим количество введенных чисел
    cout << "sum of numbers = " << b << endl; //выводим сумму введенных чисел
    return 0;

Leave a Reply to GalizMan Cancel reply

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