Вопрос Как без цикла заполнить массив в c++ числами от 0 до 155 с шагом 1?

Регистрация
3 Сен 2013
Сообщения
75
Репутация
0
Спасибо
0
Монет
0
Как без цикла заполнить массив в C++ числами от 0 до 155 с шагом 1?
 
#include <iostream>
#include <numeric>
using namespace std;
int main(){
int array[156]; iota(array,array+156,0);
for(int i:array)cout<<i<<' ';}
 
#include
#include
using namespace std;
int main() {
constexpr size_t n = 156;
int arr[n]{};
iota(begin(arr), end(arr), 0);
for (auto x : arr) cout
 
Генераторами, с++17 #include
#include
using namespace std;

int main() {
vector v(156);
generate(v.begin(), v.end(), [n = 0]() mutable { return n++; });

return 0;
}
 
Назад
Сверху