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
Iterator main loop enters with the value 0, therefore, the first nested loop (if we make the appropriate calculations) j = 1, j = 2, j = 3, j = 4; Since this cycle is responsible for the gaps, we'll get 4 whitespace. Then iterator(i=0) It goes down in the second cycle, wherein j = 1; The second nested loop is responsible for the '^', so the sign will indicate a time. Iterator enters the main loop with the value 1, therefore, the first nested loop j = 1, j = 2, j = 3; respectively, will be 3 whitespace. We go to the second nested loop: j = 3 j = 4 j = 5; Accordingly, the three will indicate our sign '^'. And so on…
Well no, It does not help, Yes and should not help. By and large, it only changes the redundant memory. When I was looking for some fractional number, prog “hangs”…
I read the beginning of the While loop and decided 3 the task of using it :) my solution is different from other, but it works (I'm here podredaktirovalchtoby easier and clearer to read here:
#include using namespace std; int main() { int i; // height int probel; // the number of spaces you TREL = 1; // the number of triangles int a = 1; /* Since trel postojano reset, kol – in triangles shall designate this variable */ cout << "введите высоту пирамиды" <> i; while(i) { probel = i-1; /*Qty probelov i-1 (height = 5) the number of spaces on the top floor = 4 i.t can see for yourself that it works */ while(probel) { cout << " "; // Output Blank probel–; }
while(Trel) { cout << "^"; // after writing gaps triangles Trel–; } a += 2; /*triangles pattern – 1, 3, 5, 7.. ie increases on 2*/ trel = a; // you follow the number of triangles cout << "\n"; // newline (floor of the pyramid); i–; }
return 0; } /* I tried very hard to hope you enjoyed, obraschyayte no attention to grammar mistakes and RUF. (I'm a newbie)*/
Please help to understand the problem with the triangle. I can not understand it.
Iterator main loop enters with the value 0, therefore, the first nested loop (if we make the appropriate calculations) j = 1, j = 2, j = 3, j = 4; Since this cycle is responsible for the gaps, we'll get 4 whitespace. Then iterator(i=0) It goes down in the second cycle, wherein j = 1; The second nested loop is responsible for the '^', so the sign will indicate a time.
Iterator enters the main loop with the value 1, therefore, the first nested loop j = 1, j = 2, j = 3; respectively, will be 3 whitespace. We go to the second nested loop: j = 3 j = 4 j = 5; Accordingly, the three will indicate our sign '^'. And so on…
When I enter a fractional number in an endless cycle!!!
I collect on VS 2015
This is the first problem.
try to float
try to float
Well no, It does not help, Yes and should not help. By and large, it only changes the redundant memory.
When I was looking for some fractional number, prog “hangs”…
float kr, kp;
int kt = 1, kpn = 0, ktn = 0;
cout <> kr;
Kp = No.;
for (; kp != 0; kt += 2 , kp–)
{
kpn = 0;
while(kp > kpn) {
cout < ktn) {
cout << "^"; ktn++;
}
cout << endl;
A problem with triangle(3):
#include
#include
#include
using namespace std;
int main()
{
string triangle = “^”;
int height, i = 0;
int eve = 30;
cout <> height;
while (i < height)
{
cout << setw(eve) << triangle << endl;
triangle += "^^";
i ;
eve++;
}
system("pause");
return 0;
}
I read the beginning of the While loop and decided 3 the task of using it :) my solution is different from other, but it works (I'm here podredaktirovalchtoby easier and clearer to read here:
#include
using namespace std;
int main()
{
int i; // height
int probel; // the number of spaces
you TREL = 1; // the number of triangles
int a = 1; /* Since trel postojano reset, kol – in triangles
shall designate this variable */
cout << "введите высоту пирамиды" <> i;
while(i) {
probel = i-1; /*Qty probelov i-1 (height = 5) the number of spaces on the top floor = 4 i.t can see for yourself that it works */
while(probel) {
cout << " "; // Output Blank
probel–;
}
while(Trel) {
cout << "^"; // after writing gaps triangles
Trel–;
}
a += 2; /*triangles pattern – 1, 3, 5, 7.. ie increases
on 2*/
trel = a; // you follow the number of triangles
cout << "\n"; // newline (floor of the pyramid);
i–;
}
return 0;
} /* I tried very hard to hope you enjoyed, obraschyayte no attention to grammar mistakes and RUF. (I'm a newbie)*/
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “ru”);
cout << "программа для вывода треугольника"<<endl;
cout <> height;
for (int j = 0; j < height; j )
{
for (int i = 1; i < height * 2; i )
{
if (i height+j)
cout << " ";
else
cout << "^";
}
cout << endl;
}
}// задачка с треугольником(в vs 2017)
#include “pch.h”
#include
using namespace std;
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;
}