program to find sum of array elements
- C++ PROGRAM TO FIND SUM OF ARRAY ELEMENTS
- #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: mohamedsafeer
- //http://4CSSSM.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();
- }
Comments
Post a Comment