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

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

  1. #include
    using namespace std;

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

    double min_digit = 0;
    double max_digit = 0;
    double sum_digit = 0;

    cout <> min_digit;
    cout <> max_digit;

    for (int i = min_digit; i <= max_digit; i )
    {
    if (i % 2 == 0)
    {
    continue;
    }
    cout << i << " " ;
    sum_digit += i;
    }

    cout << endl;
    cout << "Сумма нечетных чисел в диапазоне от " << min_digit << " to " << max_digit << " = " << sum_digit << endl;

    return 0;
    }

  2. In the first task I wrote differently, this is not a mistake? #include
    using namespace std;

    int main() {
    setlocale(LC_ALL, “”);
    int a = 0;
    int b;
    int g = 0;
    start : cout <> b;
    for (; b != 0;) {
    a++;
    g += b;
    goto start;
    }
    if (a < 5) {
    cout << "Ви ввели " << a << " number" << endl;
    }
    else {
    cout << "Ви ввели " << a << " numbers" << endl;
    }
    cout << "Сумма усіх чисел: " << g << endl;
    cout << "Середнє арифметичне усіх чисел: " << g / a << endl;

    }

  3. Hello ! Most requested ! Give a detailed description of the solution to the problem of constructing a filled triangle from symbols ! If it exists at all . because I can’t find it on the internet ! Thank you in advance , who will respond. Of course , I have my own version , however, I would like to see the specialist’s description.

Leave a Reply

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