Welcome Guest | Sign in | Register

Home > C Programming > Loops > Questions and Answers

01. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?
A. 10 B. 9
C. 0 D. 1

Answer and Explanation

Answer: 10

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. When does the code block following while(x<100) execute?
A. When x is less than one hundred B. When x is greater than one hundred
C. When x is equal to one hundred D. While it wishes

Answer and Explanation

Answer: When x is less than one hundred

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Which is not a loop structure?
A. For B. Do while
C. While D. Repeat Until

Answer and Explanation

Answer: Repeat Until

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. How many times is a do while loop guaranteed to loop?
A. 0 B. Infinitely
C. 1 D. Variable

Answer and Explanation

Answer: 1

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. The statement which prints out the values 1 to 10 on separate lines, is
A.  Statement 1
for( count = 1; count <= 10; count = count + 1)
printf("%d\n", count);
B. Statement 2
for( count = 1; count < 10; count = count + 1)
printf("%d\n", count);
C.  Statement 3
for( count = 0; count <= 9; count = count + 1)
printf("%d ", count);
D. Statement 4
for( count = 1; count <> 10; count = count + 1)
printf("%d\n", count);

Answer and Explanation

Answer:  Statement 1
for( count = 1; count <= 10; count = count + 1)
printf("%d\n", count);

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. The statement which produces the following output is, (hint: use two nested for loops)
 1
22
333
4444
55555
A. Statement 1
for(a = 1; a <= 5; a = a + 1) {
for( b = 1; b <= 5; b = b + 1)
printf("%d", b);
printf("\n");
}
B. Statement 2
for( a = 1; a <= 5; a = a + 1) {
for( b = 1; b <= a; b = b + 1)
printf("%d", a);
printf("\n");
}
C. Statement 3
for( a = 1; a <= 5; a = a + 1) {
for( b = a; b <= 5; b = b + 1)
printf("%d", b);
printf("\n");
}
D. Statement 4
for( a = 1; a <= 5; a = a + 1) {
for( b = 1; b < a; b = b + a)
printf("%d", b);
printf("\n");
}

Answer and Explanation

Answer: Statement 2
for( a = 1; a <= 5; a = a + 1) {
for( b = 1; b <= a; b = b + 1)
printf("%d", a);
printf("\n");
}

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. The statement which sums all values between 10 and 100 into a variable called total is, assuming that total has NOT been initialised to zero.
A. Statement 1
for( a = 10; a <= 100; a = a + 1)
total = total + a;
B. Statement 2
for( a = 10; a < 100; a = a + 1, total = 0)
total = total + a;
C. Statement 3
for( a = 10; a <= 100, total = 0; a = a + 1)
total = total + a;
D. Statement 4
for( a = 10, total = 0; a <= 100; a = a + 1)
total = total + a;

Answer and Explanation

Answer: Statement 4
for( a = 10, total = 0; a <= 100; a = a + 1)
total = total + a;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. The statement that prints out the character set from A-Z, is
A. Statement 1
for( a = 'A'; a < 'Z'; a = a + 1)
printf("%c", a);
B. Statement 2
for( a = 'a'; a <= 'z'; a = a + 1)
printf("%c", &a);
C. Statement 3
for( a = 'A'; a <= 'Z'; a = a + 1)
printf("%c", a);
D. Statement 4
for( a = 'Z'; a <= 'A'; a = a + 1)

Answer and Explanation

Answer: Statement 3
for( a = 'A'; a <= 'Z'; a = a + 1)
printf("%c", a);

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. The statement which prints the integer values 1 to 10 on the screen, is
12345678910
A. Statement 1
count = 1;
while( count <= 10 ) {
printf("%d", count);
count = count + 1;
}
B. Statement 2
count = 1;
while( count <= 10 ) {
printf("%d", &count);
count = count + 1;
}
C. Statement 3
count = 1;
while( count < 10 ) {
printf("%d\n", count);
count = count + 1;
}
D.  Statement 4
count = 1;
while( count <= 10 ) {
printf("%d\n", count);
count = count + 1;
}

Answer and Explanation

Answer: Statement 1
count = 1;
while( count <= 10 ) {
printf("%d", count);
count = count + 1;
}

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. How many times the below loop will run
main()
{
int i;
i=0;
do
{
--i;
printf("%d",i);
i++;
}
while(i>=0);
}
A. 1 B. Infinite
C. 0 D. Compilation Error

Answer and Explanation

Answer: Infinite

Explanation:
In every iteration value of i is decremented and then incremented so remains 0 and hence a Infinite Loop

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.