数据结构、算法与应用 (C++描述) 第二版 1.5

来源:互联网 发布:淘宝店怎么做广告 编辑:程序博客网 时间:2024/06/05 10:12
        **仅给有需要的人以参考,如有不对请纠正我**        = = 这个题目应该就是给一个数值然后依次加上数组索引值之后赋给数组相应位置。
#include<iostream>template<typename T, typename V>void iota(T a[], int va, V value){    for (int i = 0; i < va; i++)        a[i] = value + i;}int main(){    using namespace std;    int * a;    int size;    int value;    cout << "Input the size of array a: ";    cin >> size;    a = new int[size];    cout << "Enter a number: ";    cin >> value;    iota(a, size, value);    for (int i = 0; i < size; i++)        cout << a[i] << endl;    delete[]a;    return 0;}
0 0
原创粉丝点击