program to find sum of array elements


  1. C++ PROGRAM TO FIND SUM OF ARRAY ELEMENTS 


  2. #include<iostream.h>
  3. #include<conio.h>
  4. void main()
  5. {
  6. clrscr();
  7. int ar[10],n,s=0;
  8. cout<<"Enter size of the array: ";
  9. cin>>n;
  10. cout<<"Enter array element: "<<endl;
  11. for(int i=0;i<n;i++)
  12. {
  13. cout<<"Enter element "<<i<<": ";
  14. cin>>ar[i];
  15. }
  16. //Coding by: mohamedsafeer
  17. //http://4CSSSM.blogspot.com
  18. cout<<"Elements of array: "<<endl;
  19. for(i=0;i<n;i++)
  20. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  21. ///For adding all elements///
  22. for(i=0;i<n;i++)
  23. s=s+ar[i];
  24. cout<<"Sum of elements: "<<s;
  25. getch();
  26. }

Comments

Popular posts from this blog