Size of array is taken from user..Numbers are stored in the array.. and sum is determined of the elements of array..
Select To use this code as it is.. select and copy paste this code into code.cpp file :)
- #include<iostream.h>
- #include<conio.h>
- void main()
- {
- clrscr();
- int ar[10],n,s=0;
- cout<<"Enter size of the array: ";
- cin>>n;
- cout<<"Enter array element: "<<endl;
- for(int i=0;i<n;i++)
- {
- cout<<"Enter element "<<i<<": ";
- cin>>ar[i];
- }
- //Coding by: Snehil Khanor
- //http://WapCPP.blogspot.com
- cout<<"Elements of array: "<<endl;
- for(i=0;i<n;i++)
- cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
- ///For adding all elements///
- for(i=0;i<n;i++)
- s=s+ar[i];
- cout<<"Sum of elements: "<<s;
- getch();
- }
0 comments:
Post a Comment