Write a program to find maximum in array

Size of array is taken from user..elements are entered by user..biggest ellement is displayed.


Select To use this code as it is.. select and copy paste this code into code.cpp file :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int ar[10],n,max;
  7. cout<<"Enter size of the array: ";
  8. cin>>n;
  9. cout<<"Enter array element: "<<endl;
  10. for(int i=0;i<n;i++)
  11. {
  12. cout<<"Enter element "<<i<<": ";
  13. cin>>ar[i];
  14. }
  15. //Coding by: Snehil Khanor
  16. //http://WapCPP.blogspot.com
  17. cout<<"Elements of array: "<<endl;
  18. for(i=0;i<n;i++)
  19. cout<<"Element at index number "<<i<<" is: "<<ar[i]<<endl;
  20. ////To find MAX////
  21. max=ar[0];
  22. for(i=0;i<n;i++)
  23. {
  24. if(max<ar[i])
  25. max=ar[i];
  26. }
  27. cout<<"Maximum in the array is "<<max;
  28. getch();
  29. }

Check out this stream