< previous page
page_640
next page >
Page 640
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:
a. Set
count
to all zeros.
b. Set
rainbow
to all
WHITE
.
c. Count the number of times
GREEN
appears in
rainbow
.
d. Print the value in
count
indexed by
BLUE
.
e. Total the values in
count
.
7. What is the output of the following program? The data for the program is given below it.
#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:
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 >