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
When I studied the topic, started tasks, I begin to solve, something about estimated, compiled, Did not work out, I take into account the error, edited .. and so several times, until you get the right solution. This procedure is correct? Or I should initially consider all job, and then start writing program. I am learning from scratch, in principle, all tasks are solved itself, but, sometimes, 1-2 hours spent on each. This is normal, or I'm hopeless?)
3. Calculate the value of the cube root with accuracy , using Newton's iterative formula . Count the number of iterations, for which the desired accuracy is achieved. The accuracy of the calculation is defined as the modulus of the difference between two consecutive iterations.
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
int height;
int a, b;
cout <> height;
a = b = height;
for (int i = 0; i < height; i++) {
for (int j = 0; j = a && j <= b) cout << "^";
else cout << " ";
}
a--;
b++;
cout << endl;
}
return 0;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, "ru");
int min_digit = 0;
int max_digit = 0;
int total_digit = 0;
cout << "Введите диапзон!" << endl;
cout <> min_digit;
cout <> max_digit;
while (min_digit > max_digit)
{
cout << "Минимальное значение не может быть больше максимального!" <> max_digit;
}
for (int i = 0; i != (max_digit - min_digit); i++)
{
if ((min_digit + i) % 2)
{
cout << min_digit + i << endl;
total_digit += (min_digit + i);
}
}
cout << total_digit << endl;
return 0;
}
Fine?
#include “stdafx.h”
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, “rus”);
int a = 1, count = -1, sum = 0, av = 0;
while (a!=0)
{
cout <> a;
sum += a;
++ account;
}
of = sum / account;
cout << "Сумма чисел : " << sum << endl;
cout << "Количество чисел : " << account << endl;
cout << "Среднее арифметическое : " << of << endl;
system ("pause");
}
The latter problem is pretty simple. It can be implemented in C and:
strange reasoning…
What, any difficulty the task can not be implemented in pure C?
When I studied the topic, started tasks, I begin to solve, something about estimated, compiled, Did not work out, I take into account the error, edited ..
and so several times, until you get the right solution. This procedure is correct? Or I should initially consider all job, and then start writing program. I am learning from scratch, in principle, all tasks are solved itself, but, sometimes, 1-2 hours spent on each. This is normal, or I'm hopeless?)
This procedure is correct – programs always work out the method of successive approximations.
Although consider in advance the order follow-up is also useful: then the number will be less than these approximations.
3. Calculate the value of the cube root with accuracy , using Newton's iterative formula . Count the number of iterations, for which the desired accuracy is achieved. The accuracy of the calculation is defined as the modulus of the difference between two consecutive iterations.
Is there a code to find the maximum number entered?(1 a task)?
If there is, prompt, you are welcome
IMHO the task 1 through a for loop(;;) easier to do, but using while is somehow not very clear.
Finally figured out how to do it using while:
In many publications and different programming languages, the while loop is considered a more general form, than a for loop.