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
Help to solve 2 tasks 1) enter a number. Get another number by removing the digits 0 and 1 maintaining the order of the digits. Example(201304, результат 234) 2) serial input numbers to find their product, entry stop if the work was still 0.
only action “draw” It refers to graphics, but has almost nothing to do with C ++ language. It all depends on whether, that you use: a). operating system (Windows, Linux, et al.), b). from graphics system (libraries) in which you want to write it all (Qt, GTK+, wxWidget, MFC, or even in the terminal pseudographics). Graphics does not have a part of the C ++ and libraries. The very formulation of the problem so – It is not correct!
everything is working, but really turned zamorochitsya. certainly have a lot of excess. to your fine, practical and quick solutions to me far. while newcomer. but as in any way did! Hooray!
#include using namespace std;
void main() { setlocale(LC_ALL, “ru”); int height; int a = 0; int c = 0; int f = 0; int x = 0; int z = 0; cout <> height; int d = height; do { if (a < height – 1) { do { cout << " "; c++; } while (c < height – 1); } x++; c = x; do { cout < 0) { do { cout < 0); } } while (d != height); cout << endl; with ++; f = z; a++; } while (a < height); }
Also not been able to see a pattern in the triangle, and because of this extra cycle and extra variables :|
#include #include using namespace std;
int main(int argc, char** argv) { int x; int n = 1; int num = 1; cout <> x; for (int i = 1; i < x; ++i) a = a + 2; while (x != 0) { for(int j=1; j < on one; ++j) cout << " "; for(int i=0; i < n; ++i) cout << "^"; cout << "\n"; n = n + 2; a = a – 1; –x; } system ("pause"); return 0; }
As the lesson was called “while and do while loops” did the 3rd task with their help. I had to tinker because the for loop is more compact and more convenient for this #include using namespace std;
int main() { setlocale(LC_ALL, “rus”);
int width = 1; int j = 1; int height = 0; int i = 1; int space = 1;
cout << "Введите высоту равноберенного треугольника" <> height;
do { while (probel <= height – i) { cout << " "; probel++; } while (j <= width) { cout << "^"; j ;
} cout << endl; i ; width += 2; j = 1; space = 1; } while (i <= height);
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “RUS”);
int countNum = 0;
int sum = 0;
int avarage = 0;
int number = 1;
while(number != 0)
{
cout <> number;
sum += number;
countNum++;
avarage += number / 2;
if(number != 0)
cout << "Чтобы остановить ввод, enter 0." << endl;
}
cout << "Количество чисел: " << countNum << endl;
cout << "Общая сумма чисел: " << sum << endl;
cout << "Средне арифметическое: " << avarage << endl;
return 0;
}
Help to solve 2 tasks
1) enter a number. Get another number by removing the digits 0 and 1 maintaining the order of the digits. Example(201304, результат 234)
2) serial input numbers to find their product, entry stop if the work was still 0.
to understand how the first problem is solved through the input array, and a second cycle for any while, or.
example solutions 2 tasks
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int i,sum;
while (sum != 0)
{
cout << "Введите число" <> i;
sum = sum + i;
cout << sum << endl;
}
cout << "Сумма чисел = " << sum << endl;
return 0;
}
I do not know how to write here the normal komenty (instead of copy-paste script garbage copied)
Comments here Editor does not allow normally enter the code in C ++.
#include
using namespace std;
int main()
{
char ch;
int height;
cout<>height;
cout<>ch;
for (int i = 0; i= 0; j–)
{
cout << " ";
}
for (int j = 0; j < i+1+i; j )
{
cout << ch;
}
cout << endl;
}
}
How to write C ++ code to do while loop? *draw a triangle and a rectangle, so inside they were empty
only action “draw” It refers to graphics, but has almost nothing to do with C ++ language. It all depends on whether, that you use: a). operating system (Windows, Linux, et al.), b). from graphics system (libraries) in which you want to write it all (Qt, GTK+, wxWidget, MFC, or even in the terminal pseudographics).
Graphics does not have a part of the C ++ and libraries.
The very formulation of the problem so – It is not correct!
everything is working, but really turned zamorochitsya. certainly have a lot of excess. to your fine, practical and quick solutions to me far. while newcomer. but as in any way did! Hooray!
#include
using namespace std;
void main()
{
setlocale(LC_ALL, “ru”);
int height;
int a = 0;
int c = 0;
int f = 0;
int x = 0;
int z = 0;
cout <> height;
int d = height;
do
{
if (a < height – 1)
{
do
{
cout << " ";
c++;
} while (c < height – 1);
}
x++;
c = x;
do
{
cout < 0)
{
do
{
cout < 0);
}
} while (d != height);
cout << endl;
with ++;
f = z;
a++;
} while (a < height);
}
#include
#include
using namespace std;
void main()
{
setlocale(LC_ALL, “rus”);
int n = 3;
double *mass = new double[n];
int i = 1,sum=0,ch=0,sred;
mass[0] = 1;
while (mass[i-1] != 0)
{
cout << "Введите " << i <> mass[i];
sum = sum + mass[i];
if(mass[i]!=0)
ch = ch + 1;
n++;
i ;
}
sred = sum / ch;
cout << "Среднее арифметическое из " << ch << " number = " << sred << " . Their total amount = " << sum << endl;
delete mass;
system("pause");
}
Also not been able to see a pattern in the triangle, and because of this extra cycle and extra variables :|
#include
#include
using namespace std;
int main(int argc, char** argv)
{
int x;
int n = 1;
int num = 1;
cout <> x;
for (int i = 1; i < x; ++i)
a = a + 2;
while (x != 0)
{
for(int j=1; j < on one; ++j)
cout << " ";
for(int i=0; i < n; ++i)
cout << "^";
cout << "\n";
n = n + 2;
a = a – 1;
–x;
}
system ("pause");
return 0;
}
As the lesson was called “while and do while loops” did the 3rd task with their help. I had to tinker because the for loop is more compact and more convenient for this
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int width = 1;
int j = 1;
int height = 0;
int i = 1;
int space = 1;
cout << "Введите высоту равноберенного треугольника" <> height;
do {
while (probel <= height – i)
{
cout << " ";
probel++;
}
while (j <= width)
{
cout << "^";
j ;
}
cout << endl;
i ;
width += 2;
j = 1;
space = 1;
} while (i <= height);
system("pause");
return 0;
}