#include <iostream>
using namespace std;
int main()
{
int t, n;
cin >> t >> n;
int a[n];
for (int i = 0; i < n; ++i){
int mark;
cin >> mark;
a[i] = mark;
}
for (int i = -t; i <= t; ++i){
cout << i << ": ";
for (int j = 0; j < n; ++j)
if(a[j] == i)cout << j + 1 << " ";
cout << endl;
}
return 0;
}
Объяснение:
не знаю, что тут объяснять, вроде все просто.
P.s. Если , дайте , лучший ответ и жмякните на " ". Это мотивирует продолжать давать ответы.
человеку из комментариев за поправки.
#include <iostream>
#include <cstdlib>
#include <ctime>
typedef int datatype;
void init_array(datatype* arr, int SIZE)
{
for (int i = 0; i < SIZE; ++i)
arr[i] = rand() % 100;
}
void show_array(datatype* arr, int SIZE)
{
std::cout << "array: ";
for (int i = 0; i < SIZE; ++i)
std::cout << arr[i] << " ";
std::cout << "\n";
}
datatype find_sum(datatype* arr, int SIZE)
{
datatype sum = 0;
for (int i = 0; i < SIZE; ++i)
sum += arr[i];
return sum;
}
int main()
{
std::cout << "enter a size of the array: ";
int SIZE;
std::cin >> SIZE;
datatype *arr = new datatype[SIZE];
srand(time(NULL));
init_array(arr, SIZE);
show_array(arr, SIZE);
std::cout << "sum of elements: " << find_sum(arr, SIZE) << "\n";
delete[] arr;
return 0;
}