Revision Programs

Set 1

Number Based Problems

1. Sequence Construct

  1. Input a number, reverse (change) its sign (positive/negative) and print it.

2. Conditional Construct: Selection Statement

if

  1. Input a number, if it is negative make it positive. Print the number.

if else

  1. Input a number, check and print whether it is positive or not positive.

if else if else

  1. Input a number, check and print whether it is positive or negative or zero.

Nested if

  1. Input a number, check and print whether it is Positive Even or Not Positive Even.

Nested if else if else

  1. Check whether an input number it is Positive Even or Positive Odd or Negative Even or Negative Odd or Zero.

switch case

  1. Write a menu driven program:
    1) If an input number is negative even find its square; otherwise nothing to be done. Print the number.
    2) If an input number is positive odd find its cube; otherwise nothing to be done. Print the number.

3. Iterative Construct (Loop):

for

  1. Input n numbers, check whether they are positive or negative or zero. Count them separately.

Remaining exercises will be opened after being discussed in the class

while

  1. Input n numbers, check whether they are positive or negative or zero. Count them separately.

do while

  1. Input some numbers, check whether positive or negative or zero. Find sum and product of them separately.