Ответ:
#include <iostream>
#include <time.h>
#include <iomanip>
using namespace std;
int main()
{
int a[20];
int i, ibeg, iend, s;
setlocale(LC_ALL, "Russian");
srand(time(NULL));
for (i = 0; i < 20; i++) {
a[i] = (double)rand() / (RAND_MAX + 1) * 10;
cout << a[i] << " ";
}
ibeg = -1;
if (a[i] == 0) {
ibeg = i;
break;
iend = -1;
for (i = 20; i > 0; i--) {
iend = i;
if (ibeg != -1 && iend != -1) {
s = 0;
for (i = ibeg + 1; i < iend; i++)
s += a[i];
cout << "\nСумма = " << s << "\n";
else
cout << "\nНулевые элементы не найдены.\n";
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Ответ:
#include <iostream>
#include <time.h>
#include <iomanip>
using namespace std;
int main()
{
int a[20];
int i, ibeg, iend, s;
setlocale(LC_ALL, "Russian");
srand(time(NULL));
for (i = 0; i < 20; i++) {
a[i] = (double)rand() / (RAND_MAX + 1) * 10;
cout << a[i] << " ";
}
ibeg = -1;
for (i = 0; i < 20; i++) {
if (a[i] == 0) {
ibeg = i;
break;
}
}
iend = -1;
for (i = 20; i > 0; i--) {
if (a[i] == 0) {
iend = i;
break;
}
}
if (ibeg != -1 && iend != -1) {
s = 0;
for (i = ibeg + 1; i < iend; i++)
s += a[i];
cout << "\nСумма = " << s << "\n";
}
else
cout << "\nНулевые элементы не найдены.\n";
}