1 – D ARRAYS

Q1.Write C++ statements to do the following:

a. b. c. d. e.

Declare and initialize an array of scores of 20 batsmen of type int. Display the 10th component of the array scores. Display the 5th component of the array scores Set the value of the 8th component of the array scores to 35. Set the value of the 6th component of the array scores to the sum of the 9th and 12th components of the array scores. f. Set the value of the 14th component of the array scores to 2 times the value of the 7th component minus 25. g. Display the array scores so that 4 components per line are printed

2. a. Given declaration, answer the questions. int a[5] ={3, 7, 4, 9, 6}; (i). Give the value of a[4]. (ii).Give the value of a[5]. b. Given declaration, answer the questions. int a[5] = {3, 7, 4, 9, 6}; (i) What is a[1] + a[4]? (ii) What is a[0] – a[2]? (iii) What is a[0] + 2? (iv) What is a[1 + a[0]]? c. Given declaration, answer the questions int a[5] = {3, 7, 4, 9, 6}; for(i = 0; i <= 4; i = i + 1} cout<< a[4 - i]; (i) When i is 0, What is the value of a[4 – 0] (ii) When i is 2, What is the value of a[4 – 2] (iii) When i is 4, what is printed?

(iv)What is the final output of this code? d.Write a code to print the array in reverse order. 3. Give output (Please show the memory diagram/dry run) (i) #include void main() { int count = 0, a[5] = {3, 7, 4, 9, 6}, i, sum=0; for(i = 0; i <= 4; i = i + 1) if(a[i] > 5) sum = sum + a[i]; cout<< sum; } (ii) #include void main() { int count = 0, a[5] = {3, 7, 4, 9, 6}, i; for(i = 0; i <= 4; i = i + 1) if(a[i] > 5) { count = count + 1; cout< void main() { int a[5] = {3, 7, 4, 9, 6}, i, sum=0, count=0; for(i = 0; i <= 4; i = i + 1) { if( a[i] > 5 ) sum = sum + a[i]; if( a[i] <= 5 ) count = count + 1; } cout<< sum; cout<< count; }

i d arrays.pdf

Page 3 of 3. Page 3 of 3. i d arrays.pdf. i d arrays.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying i d arrays.pdf.

59KB Sizes 3 Downloads 142 Views

Recommend Documents

Download I d Tell You I Love You, But Then I d Have to ...
every school taught advanced martial arts in PE and the ... she can tap his phone, hack into his computer, and track ... sophomore year, she's beginning her most.

Download PDF I d Tell You I Love You, But Then I d ...
... But Then I d Have to Kill You (Gallagher Girls Series) ,ebook reader device I d .... You (Gallagher Girls Series) ,microsoft ebook reader I d Tell You I Love You, ...

PDF Online I d Tell You I Love You, But Then I d Have ...
... are inside this book To get more targeted content please make full text search by ... Online PDF I d Tell You I Love You, But Then I d Have to Kill You (Gallagher .... Sure, she can tap his phone, hack into his computer, and track him through ...

Page 1 - d - d - - - . . . . . a - - r at i s - 3. a of Ju i - e---Jet - a .45 JLi Ji ...
4- P Jr. (-2. st-3U-y {\ } ar. Ju 2 - 5 -- 'Y'. Ye .... C. Justif-e- st--- - “Y Y- 13 - Jus, ifle un--- Ula-i- “Y YW-. A r - af -. * - - - - - r a - 1 - ... (e.g., is ill--e G.I., ( tr. 2 - JC; i.e. if ...