[ create a new paste ] login | about

Link: http://codepad.org/2NUqtLGN    [ raw code | output | fork ]

C++, pasted on May 11:
#include <iostream>
using namespace std;


template<class T> T max(const T* data, int size) {
    T result = data[0];
    for(int i = 1 ; i < size ; i++)
        if(result < data[i])
            result = data[i];
    return result;
}
int main() {

    int a;

    cout << "How many elements array has? " <<endl;
    cin>>a;

    int *r=new int[a];
    int temp;
    for(int i=0; i<a; i++){
        cout << "Enter "<<i+1<<". element: ";
        cin >>temp;
        *(r+i)=temp;

    }
    for(int i=0; i<a; i++){
        cout<<*(r+i)<<endl;

    }


     cout << "Maximum integer is " << max(r, a) << endl;
    delete []r;
    return 0;
}


Output:
1
2
3
How many elements array has? 
std::bad_alloc: St9bad_alloc
Aborted.


Create a new paste based on this one


Comments: