< previous page page_640 next page >

Page 640
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int    count[8];
Colors cindex;                // Index for count array
Colors rainbow [MAX-LENGTH ];
int    rindex;                // Index for rainbow array
write code fragments to do the following tasks:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Set count to all zeros.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Set rainbow to all WHITE.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Count the number of times GREEN appears in rainbow.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. Print the value in count indexed by BLUE.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
e. Total the values in count.
7. What is the output of the following program? The data for the program is given below it.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
#include <iostream.h>

int main()
{
    int a[100];
    Int b[100];
    int j;
    int m;
    int sumA = 0;
    int sumB = 0;
    int sumDiff = 0;

    cin >> m;
    for (j = 0; j < m; j++)
    {
        cin >> a[j] >> b[j];
        sumA = sumA + a[j];
        sumB = sumB + b[j];
        sumDiff = sumDxff + (a[j] -  b[j]);
    }
    for (j = m - 1; j >= 0; j--)
        cout << a[j] << ' ' << b[j] << ' '
             < a[j] - b[j] < end1;
    cout << end1;
    cout << sumA << ' ' << sumB << ' ' << sumDiff << end1;
    return 0;
}
Data:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
  5
11 15
19 14
 4  2
17  6
 1  3
8. A person wrote the following code fragment, intending to print 10 20 30 40.

 
< previous page page_640 next page >