Saturday, 25 February 2012

Dynamic Array (Example)


#include <iostream>
using namespace std;
int main()
{
                int* arr=NULL;
                int size;
                cout<<"How many number u want?";
                cin>>size;
                int sum=0;
                arr=new int[size];
                for(int i=0;i<size;i++)
                {
                                cout<<"Enter number :";
                                cin>>arr[i];
                }
                for(i=0;i<size;i++)
                {
                                sum=sum+arr[i];
                }
                cout<<sum;       
                return 0;
}

No comments:

Post a Comment