Write C++ program to read and print elements of array


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #define MAX_SIZE 100 //Maximum size of the array
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int arr[MAX_SIZE]; //Declares sizr of array
  8. int i, num;
  9. cout<<"Enter size of array: ";
  10. cin>>num;
  11.  
  12. cout<<"Enter "<<num<< " elements in the array :";
  13.  
  14. //Reads size & elements in array
  15. for(i=0; i<num; i++)
  16. {
  17. cin>>arr[i];
  18. }
  19.  
  20. //Prints all elements of array
  21. cout<<"\nElements in array are: ";
  22. for(i=0; i<num; i++)
  23. {
  24. cout<<arr[i]<<"\t";
  25. }
  26.  
  27. return 0;
  28. }
  29.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts