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
not tasks, what the fuck- then, like solving problems on tskils, but in fact here from the cycles only the name, more precisely if it is more correct to express, understanding cycles will not help in solving these problems
int main(void) { double val, sum = 0, amount = 0; std::cout <> val && val) { std::cout << "Val: " << val << '\n'; ++amount; sum += val; } std::cout << "Total: " << sum << '\n'; std::cout << "Amount: " << amount << '\n'; }
SECOND
#include ; int main(void) { int begin, end; std::cout <> begin >> end && begin > end) { if (std::cin.fail()) { std::cout < end) { std::cout << "First value mast be less than second\n"; } } std::cout << "begin: " << begin << ", end " << end << '\n';
unsigned total = 0; for (int i = begin; i <= end; i ) { if (!(i % 2)) { std::cout << i << ' '; total += i; } } std::cout << "\nTotal: " << total << '\n'; }
In the last task, if you solve the same way as the authors, then there will be bugs, i entered 111 and there the line was out of order krch
отдалить надо
не туда ебнул
not tasks, what the fuck- then, like solving problems on tskils, but in fact here from the cycles only the name, more precisely if it is more correct to express, understanding cycles will not help in solving these problems
FIRST
#include
int main(void) {
double val, sum = 0, amount = 0;
std::cout <> val && val) {
std::cout << "Val: " << val << '\n';
++amount;
sum += val;
}
std::cout << "Total: " << sum << '\n';
std::cout << "Amount: " << amount << '\n';
}
SECOND
#include ;
int main(void) {
int begin, end;
std::cout <> begin >> end && begin > end)
{
if (std::cin.fail()) {
std::cout < end) {
std::cout << "First value mast be less than second\n";
}
}
std::cout << "begin: " << begin << ", end " << end << '\n';
unsigned total = 0;
for (int i = begin; i <= end; i ) {
if (!(i % 2)) {
std::cout << i << ' ';
total += i;
}
}
std::cout << "\nTotal: " << total << '\n';
}
Самое легкое решение первой задачи в минимум строк
void main()
{
setlocale(LC_ALL, “ru”);
int b;
int a = 1;
float suma = 0;
int i = 0;
for (;i < a;i )
{
a++;
cout <> b;
suma += b;
if (b == 0)
{
break;
}
}
cout << "Сумма:" << suma << endl;
cout << "Средние арефм:" << double(suma / i);
int b;
int a = 1;
float suma = 0;
int i = 0;
for (;i < a;i )
{
a++;
cout <> b;
suma += b;
if (b == 0)
{
break;
}
}
cout << "Сумма:" << suma << endl;
cout << "Средние арефм:" << double(suma / i); P.S Плохо скопировал.
аааа а это сайт удаляет лол а как тогда вставить)) , если он код убирает))
2 a task
int s;
int start_range;
int close_range;
cout <> start_range;
cout <> close_range;
for (int i = 0;i < close_range;i )
{
s=start_range % 2;
if (s !=0)
{
cout << start_range << " ";
}
if (start_range == close_range)
{
break;
}
start_range++;
3 задача с помощью do while(как написано в заголовке):
#include
using namespace std;
int main() {
setlocale(LC_ALL, “RU”);
int hight, hight1, amount1, amount = 1, str = 0;
cout <> hight;
hight1 = hight;
cout << endl;
do {
amount1 = amount;
do {
cout < 0);
do {
cout < 0);
cout << endl;
str++;
hight1 = hight – str;
amount += 2;
} while (str < hight);
return 0;
}
я конечно не эксперт, но вышло как-то так)
//task 1
#include
using namespace std;
float general = 0;
float sum = 0;
float sr;
float m;
int main() {
setlocale(LC_ALL, “RU”);
for (int i = 0; ; i )
{
cout << i + 1 <> m;
if (m) {
sum += m;
general++;
}
else
{
sr = sum / general;
cout << "\nВсего чисел было: " << general << endl << "Общая сумма чисел: " << sum << endl;
cout << "Среднее арифметическое: " << sr << endl;
break;
}
}
return 0;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int digit = 0;
double amount_digit = 0;
double sum_digit = 0;
cout << "Введите числа для расчета.\n";
cout << "0 – закончить ввод чисел.\n\n";
for (amount_digit = 1; ; amount_digit++)
{
cout << "Введите " << amount_digit <> digit;
sum_digit += digit;
{
if (digit)
amount_digit;
else if (digit == 0)
{
amount_digit–;
break;
}
}
}
cout << "Было введено чисел – " << amount_digit << endl;
cout << "Сумма всех чисел равна – " << sum_digit << endl;
cout << "Среднее арфиметическое – " << sum_digit / amount_digit << endl;
return 0;
}