1. What will be the output from each of the following lines of code? a) int x =
ID: 3543146 • Letter: 1
Question
1. What will be the output from each of the following lines of code?
a) int x = 12;
while ( x > 8 )
{
printf( "%d ", x );
}
b) for ( int x = 12; x >= 7; )
printf( "%d ", x );
c) int x = 12;
while ( x >= 10 )
{
printf( "%d ", x );
x--;
}
d) int x = 12;
do
{
printf( "%d ", x );
x--;
} while ( x <= 8 );
e) for ( int x = 12; x >= 7; --x )
printf( "%d ", x );
2. Write a for loop that will produce each of the following sequences:
a) 6, 8, 10, 12, 14,
Explanation / Answer
a . 12
12
12
12
12
.
.
.
.
.invinite loop
b. 12
12
......
.
.
.
INFINITE LOOp
c . 12
11
10
d . 12
e . 12
11
10
9
8
7
2 .
a.
for ( int x = 6 ;x <= 66; ){
printf( "%d ", x );
x=x+2;}
b
for ( int x = 0 ;x < 50;x++ ){
printf( "%d ",( (2*x) + x+1) );
}
c.
int sum=0;
for ( int x = 0;x <50;x++ ){
printf( "%d ", (2*x) + x+1 );
sum+=(2*x) + x+1;
}
d . int sum =0,i=290,count=0;
float avg=0;
while(i<=842){
count++;
sum+=i;
i+=2;
}
avg = (float)sum/count;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.