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.
View code
задача do while c++
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
30
31
32
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intamountDigits=0;// количество введенных чисел
doubletotalSum=0;// общая сумма
doubledigit=0;//
cout<<"Введите числа, для расчета (выйти - 0)\n\n";
do
{
cout<<"Число "<<amountDigits+1<<" = ";
cin>>digit;
if(digit)// если digit любое значение кроме 0(false)
{
amountDigits++;
totalSum+=digit;
}
}while(digit);// пока digit любое значение отличное от 0
And in this form the task is practically not complicated. … but requires a fair amount of ingenuity at the production level, because the standard deviation must be calculated in the same single cycle, as is the accumulation of the amount, and when the average is still unknown. Because when the sequence is counted, for example, 10000 values (which is quite common in real experiments) no one will allow you to store this lot of values for a repeated loop.
int main() { int i = 1; int sum = 0; while (i != 0) { cout << "Enter number. If you want to stop, type 0: " <> i; sum = sum + i; } cout << "And the sum of your numbers is ..." << sum << " !" << endl; system("pause"); return 0; }
//Переменные int iMinValue(0); // Минимальное значение диапозона int iMaxValue(0); // Максимальное значение диапозона int iSumValue(0); // Сумма нечетных чисел в диапозоне
//Запрос на ввод диапозона чисел cout << iMinValue; cout << iMaxValue; cout << "Нечетные числа в диапозоне от " << iMinValue << " до " << iMaxValue << ": ";
// Выводим все нечетные числа диапозона for (int i = iMinValue; i < iMaxValue + 1; i++) { if (i % 2 != 0) // Если остаток от деления не равен 0, то выводим число в ряд { cout << i << " "; // Выводим ряд нечетных чисел из диапозона iSumValue += i; // Записываем сумму нечетных чисел } } cout << endl; cout << "Сумма нечетных чисел: "; cout << iSumValue; cout << endl; }
Don't mock me… there's only 12 lines of code with loops, who puzzled you. I'll do you a big favor, if I don't comment, and you will carefully analyze this code line by line and understand, what's what. Let's, the height of the triangle is 4 (height = 4). Just imagine, what happens to this variable in loops (go through them mentally step by step ). And that, that the first inner loop draws spaces, and the second characters – it's obvious.
I agree on both points, but you can complicate the task later.
And in this form the task is practically not complicated. … but requires a fair amount of ingenuity at the production level, because the standard deviation must be calculated in the same single cycle, as is the accumulation of the amount, and when the average is still unknown. Because when the sequence is counted, for example, 10000 values (which is quite common in real experiments) no one will allow you to store this lot of values for a repeated loop.
Ahahaha, and I did the first thing
#include#include
using namespace std;
int main()
{
int i = 1;
int sum = 0;
while (i != 0) {
cout << "Enter number. If you want to stop, type 0: " <> i;
sum = sum + i;
}
cout << "And the sum of your numbers is ..." << sum << " !" << endl;
system("pause");
return 0;
}
Explain, you are welcome, third task. I don't understand anything.
Guys, please help me, I need to make a Christmas tree with a for loop
Just look at the third problem. Looks a lot like a Christmas tree
My solution to the second problem
#includeusing namespace std;
int main (){
setlocale (LC_ALL, "rus");
//Переменные
int iMinValue(0); // Минимальное значение диапозона
int iMaxValue(0); // Максимальное значение диапозона
int iSumValue(0); // Сумма нечетных чисел в диапозоне
//Запрос на ввод диапозона чисел
cout << iMinValue;
cout << iMaxValue;
cout << "Нечетные числа в диапозоне от " << iMinValue << " до " << iMaxValue << ": ";
// Выводим все нечетные числа диапозона
for (int i = iMinValue; i < iMaxValue + 1; i++)
{
if (i % 2 != 0) // Если остаток от деления не равен 0, то выводим число в ряд
{
cout << i << " "; // Выводим ряд нечетных чисел из диапозона
iSumValue += i; // Записываем сумму нечетных чисел
}
}
cout << endl;
cout << "Сумма нечетных чисел: ";
cout << iSumValue;
cout << endl;
}
Guys, please tell me for the third task how to finish the stump to the pyramid so that it turns out to be a yolka
Reply from Stilet:
Write in thread:
at:
setlocale(LC_ALL, “C”);
for (int i = 0; i < height/2+3; i++){ cout.width(height/2+3); for (int j = 1; j < 6; j++) cout<<(char)2510; cout << endl; }
Help, please with the third task. Comment on the solution.
I understand so, no one solved the third problem on their own, and the admin doesn’t care about requests to comment on the decision.
Don't mock me… there's only 12 lines of code with loops, who puzzled you. I'll do you a big favor, if I don't comment, and you will carefully analyze this code line by line and understand, what's what.
Let's, the height of the triangle is 4 (height = 4). Just imagine, what happens to this variable in loops (go through them mentally step by step ). And that, that the first inner loop draws spaces, and the second characters – it's obvious.