DevelopersSociety

Tuesday, December 9, 2014

C++ Tutorial- Program- 11- Arrays- One Dimention


Code:

#include <iostream.h>   
#include <iomanip.h>   //we use this header file for set w OR Width 
main()
{
   int arr[ 10 ]; // its an integer type array of size 10

/*initialize elements of (array) i.e start with 0 and n-1 means 0to9         
  for sum using for loop*/
  
   for ( int i = 0; i < 10; i++ )
   {
     arr[ i ] = i + 100; 
   // i.e calculation 100 =0 + 100 to 109= 9+100
   }
   cout << "Array Members" << setw( 12 ) << "Values" << endl;

   // again for loop for output/ display                      
   for ( int j = 0; j < 10; j++ )
   {
      cout << setw( 6 )<< j << setw( 17 ) << arr[ j ] << endl;
   }
   return 0;}

Output:


No comments:

Post a Comment