Tracing Assignment (Arrays)
Name: ____________________________
Score: ____________
Course/Yr/Sec.______________________
_____________
Tracing:
Date:
Trace the output of the following program segments.
#1
Tracing:
#include<stdio.h>
#include<conio.h>
sw
int a[6] = {3,5,9,2,7,1}, b[6]={2,6,4,0,5,7};
int c[10],x,sw,i,e;
main() {
for(i=0;i<6;i++)
c[i]= a[i] * b[5-1];
while(i<=10) {
sw=0;
for(x=0;x<6;x++){
for(e=0;e<6;e++){
if(b[x] == a[e])
sw=1;
}
if(sw!=1)
{
c[i] = b[x];
i++;
}
else
break;
}
if(sw==1)
[7] [8] [9]
break;
}
for (x=0; x<i;x++)
printf("%d\n",c[x]);
getch();
}
Output:
a [0] [1] [2] [3] [4] [5]
b [0] [1] [2] [3] [4] [5]
c [0] [1] [2] [3] [4] [5] [6]