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
Write a program, which print a body depending on the time, if it falls from a height H from the initial skorostyuV0. Count the number of time points, when the current altitude mensheH / 2.
#include using namespace std; int main() { setlocale(LC_ALL, “rus”); int num, sum = 0, i = 0; while (on one != 0) { for (i;;++i) { cout <> on one; sum + = num; ++i; } } cout << "Общая сумма введенных чисел " << sum; cout << "\nКоличество чисел " << i << endl; cout << "Среднее арифметическое " << sum / i << endl; return 0; }
Hi!
Here is my simplified version. I copied the wrong top)
int main()
{
int height;
cout <> height;
for (int i = 1; i <= height; i )
{
for (int j = 1; j = height – i + 1) && (j <= height + i – 1)) ? cout << "^" : cout << " ";
}
cout << endl;
}
return 0;
}
Что-то не работает твой упрощенный вариант
the first problem through better and easier to solve for
primarily through better and easier to solve fo
Write a program, which print a body depending on the time, if it falls from a height H from the initial skorostyuV0. Count the number of time points, when the current altitude mensheH / 2.
Если кому интересно разобраться в альтернативе:
#include
using namespace std;
int main()
{
int height = 0;
cout <> height;
for (int i = 0; i < height ; i )
{
for (int j = 0; j < height + i; j )
{
if (j < height – i – 1)
cout << " ";
else
cout << "^";
}
cout << endl;
}
system ("pause");
return 0;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int num, sum = 0, i = 0;
while (on one != 0)
{
for (i;;++i)
{
cout <> on one;
sum + = num;
++i;
}
}
cout << "Общая сумма введенных чисел " << sum;
cout << "\nКоличество чисел " << i << endl;
cout << "Среднее арифметическое " << sum / i << endl;
return 0;
}
using namespace std;
int num1, num2, sum;
int main()
{
setlocale(LC_ALL, “rus”);
do
{
cout <> num1;
cout <> num2;
} while (num1 > num2);
for (num1; num1 <= num2; ++num1)
{
if (num1 % 2 != 0)
{
sum += num1;
}
}
cout << "\nСумма нечетных чисел равна = " << sum << endl;
return 0;
}
вот еще вариант задачи с треугольником
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int a;
int i=0, j=0;
cout <> a;
for(i=0;i<a;i )
{
for(j=1;j= a – i && j <= a + i) cout << "^";
else cout << " ";
}
cout<<endl;
}
return 0;
}
крайне криво вставляется код.