Professional Documents
Culture Documents
CS402 Lab 8
CS402 Lab 8
CS402 Lab 8
Identify the output and show the steps of the following program segments:
(a) main()
{
int i, j=0;
int aryA[3]={0}, aryB[10]={2,3,1,2,2,3,1,2,1,3};
for(i=0; i<10; i++)
{ if (aryB[i]==1)
aryA[0]++;
else if (aryB[i]==2)
aryA[1]++;
else if (aryB[i]==3) aryA[2]++;
j+=aryB[i];
}
cout<<aryA[0]<<" "<<aryA[1]<<" "<<aryA[2]<<endl;
}
0 T F 0 Element 0 = 0 1= 0+1
1 T T 1 Element 1 = 1 2= 1+1
2 T F 0 Element 2 = 2 3= 2+1
3 T T 1 Element 3 = 3 4= 3+1
4 T F 0 Element 4 = 4 5= 4+1
5 T T 1 Element 5 = 5 6= 5+1
6 T F 0 Element 6 = 6 7= 6+1
7 T T 1 Element 7 = 7 8= 7+1
8 T F 0 Element 8 = 8 9= 8+1
10 - - - - -
Element 0 = 0
Element 1 = 1
Element 2 = 2
Element 3 = 3
Element 4 = 4
Element 5 = 5
Element 6 = 6
Element 7 = 7
Element 8 = 8
Element 9 = 9
No.1 = 11
No.2 = 12
No.3 = 13
No.4 = 14
No.5 = 15
No.1 = 0
No.2 = 0
No.3 = 0
No.4 = 0
No.5 = 0
2. Answer the following questions regarding an array called numbers.
int SIZE=10;
numbers[3]
numbers[2]=72.5;
array by reading the values from the user and print all the array
elements.
numbers[i]= number[i];