II-110 Programming Concepts
OUTPUT:
Print the numbers and their cubes
1 1
2 8
3 27
4 64
5 125
6 216
7 343
8 512
9 729
10 1000
Explanation: Here, the mathematical function pow (x, 3) is used. Its meaning is to calculate the third
power of x. With this function, we get the value of y = x
3
. For use of the pow () function, we have to
include math.h header file.
26. What is the difference between 'while' and 'do-while' loops?
Ans:
S. No. 'while' loop 'do-while' loop
1 Condition is specified at the top. Condition is mentioned at the bottom.
2 Body statement(s) is/are executed
when condition is satisfied.
Body statement(s) execute(s) even when condition is false.
3 No brackets for a single statement. Brackets are essential even when a single statement exits.
4 It is entry controlled loop. It is exit controlled loop.
27. What happens if you create a loop that never ends?
Ans: If we create a loop that never ends, then the execution will not stop and may be the program will
close automatically due to crashing of system stack.
28. Is it possible to nest 'while' loop within 'for' loops?
Ans: Yes, we can nest 'while' loop within 'for' loop, because there is no limitation on the state-
ments that can be written inside the block of loop statement, we can write any statements enclosed in
loop block.
29. How do you choose between 'while' and 'for' loops?
Ans: When we do not want to initialize any variables at the start of loop statement or we do not want
to perform any repetitive operation after each execution of loop statement, the 'while' statement is
used; otherwise, we prefer to use 'for' loop statement. Both of these statements can be used alter-
nately with very less overhead.
30. What is the difference between (!0) and (!1)?
Ans: The (!0) condition is the condition that will never become false and (!1) is the condition that is
always false, which is equivalent to Boolean values 1 and 0, respectively.
M06_ITL-ESL4791_02_SE_C06.indd 110 12/22/2012 5:02:21 PM