Lab Excercise Chapter Three

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 4

Exercises MCQ

(1) The statement i++; is equivalent to


(a) i = i + i; (b) i = i + 1; (c) i = i - 1;
(d) i --;
(2) What's wrong? for (int k = 2, k <=12, k++)
(a) the increment should always be ++k
(b) the variable must always be the letter i when using a for
loop
(c) there should be a semicolon at the end of the statement
(c) the commas should be semicolons

(3) A looping process that checks the test condition at the end of loop?
(a) for while (b) do-while (c) while (d) none
(4) A looping process is best used when the number of iterations is
known Chapter 3 - Part II
1
Exercises MCQ (cont’d)
(5) A continue statement causes execution to skip to
(a) The return 0; statement
(b) The first statement after the loop
(c) The statement following the continue statement
(d) The next iteration of the loop

(6) A break statement causes execution to skip to


(a) The return 0; statement
(b) The first statement after the loop
(c) The statement following the continue statement
(d) The next iteration of the loop
(e) The statement outside the loop
2
Chapter 3 - Part II
Practical Exercises
1. Write a program to print first n natural numbers and their sum.
2. Write a program to calculate the factorial of an integer.
3. Write a program that prints 1 2 4 8 16 32 64 128.
4. Write a program to check whether the given number is palindrome
or not.
5. Write a program to generate divisors of an integer.
6. Write a program to find whether a given number is odd or even.
The program should continue as long as the user wants.
7. Write a program to print Fibonacci series i.e.,0 1 1 2 3 5 8….
8. Write a program to check whether the entered number is
Armstrong or not. 3
Chapter 3 - Part II
Practical Exercises (cont’d)
9. Write a program to print largest even and largest odd
number from a list of numbers entered. The list
terminates as soon as one enters 0(zero).
10. Write a program to display Pythagorean triplets up to 100.
11. Write a program to calculate average of 10 numbers.
12. Write programs to produce the following designs

4
Chapter 3 - Part II

You might also like