To input numbers into an array and output after. : Array « Data Structure « C++






To input numbers into an array and output after.

To input numbers into an array and output after.
 
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   const int Length = 10;
   float arr[Length], x;
   int i, cnt;
   cout << "Enter up to 10 numbers \n"
        << "(Quit with a letter):" << endl;
   for( i = 0; i < Length  &&  cin >> x; ++i)
      arr[i] = x;
   cnt = i;
   cout << "The given numbers:\n" << endl;
   for( i = 0; i < cnt; ++i)
      cout << setw(10) << arr[i];
   cout << endl;
   return 0;
}

           
         
  








Related examples in the same category

1.Using a Variable Pointer to Point to an ArrayUsing a Variable Pointer to Point to an Array
2.Array InitializationArray Initialization
3.Assigning and Displaying Array ValuesAssigning and Displaying Array Values
4.Using the cin and cout Objects with ArraysUsing the cin and cout Objects with Arrays
5.cin and cout work with char arraycin and cout work with char array
6.Outputs addresses and values of array elements.Outputs addresses and values of array elements.
7.Array based on int pointer