H main intc100 example3 do intzi0 cinz

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tializing an Array int age [ ] = { 1,2,3,4,5,6,7,8,9,10 } ; for ( i = 0 ; i < 10 ; i ++ ) ‘ i ‘ will have value from 0 to 9 Example: 3 #include < iostream.h > main ( ) { int c [ 100 ] ; } Example: 3 do { int z , i = 0 ; cin >> z ; if ( z != ­1 ) c[ i ] = z ; assignment statement Example 3 i ++ ; } while ( z != ­1 && i < 100 ) ; cout << “ The total number of positive integers entered by user is “ << i ­1; Copying Arrays – Data types should be identical – Size should be same int a [ 10 ] ; int b [ 10 ] ; Copying Arrays To copy from array “ a ” to array “ b ” : b [ 0 ] = a [ 0 ] ; b [ 1 ] = a [ 1 ] ; b [ 2 ] = a [ 2 ] ; b [ 3 ] = a [ 3 ] ; … … … … … … b [ 10 ] = a [ 10 ] ; Copying Arrays for ( i =0 ; i < 10 ; i ++ ) b [ i ] = a [ i ] ; Example: 4 int a [ 10 ] ; int arraySize =10 ; Take the sum of squares of 10 different numbers which are stored in an array int sumOfSquares = 0 ; for ( i = 0 ; i < arraySize ; i ++ ) { sumOfSquares = sumOfSquares + a [ i ] * a [ i ] ; } int z ; int a [ 10...
View Full Document

This note was uploaded on 01/12/2010 for the course CS CS 201 taught by Professor Dr.naveedmalik during the Spring '09 term at Virtual University of Pakistan.

Ask a homework question - tutors are online