You are on page 1of 6

Exercises

1. Write a program in C++ to add two numbers & print result, assume any two numbers.
2. Write a program to print following text.

3. Write a program to display the following output using a single cout statement.

4. Write a program to print Pyramid & Horizontal Diamond using escape sequences.

Figure 1 Example of Diamond Pattern


using star (*)

5. Write and run a program that performs the following steps:


• Calculating the equivalent Celsius temperature using the formula: (5 / 9) (f -
32)
• Assume any value for Fahrenheit temperature.
• Display Output.

1. Write a C program to accept two integers and check whether they are equal or not.
2. Write a program that prompts the user to input a number. The program should then
output the number and a message saying whether the number is positive, negative,
or zero.
3. Write a program that prompts the user to input four numbers. The program should
then output the numbers in ascending order.
4. Write a program in C to read any Month Number in integer and display Month
name in the word.
5. Write a program in C to calculate and print the Electricity bill of a given customer.
The customer id., name and unit consumed by the user should be taken from the
keyboard and display the total amount to pay to the customer. The charge are as
follow :

Unit Charge/unit

upto 199 @1.20

200 and above but less than @1.50


400

400 and above but less than @1.80

600

600 and above @2.00

If bill exceeds Rs. 400 then a surcharge of 15% will be charged and the minimum bill
should be of Rs. 100/-

Sample Input :
1001
James
800
Sample Output:
Customer IDNO :1001
Customer Name :James
Units Consumed :800
Amount Charges @Rs. 2.00 per unit : 1600.00
Surcharge Amount : 240.00
Net Amount Paid By the Customer : 1840.00
6. Write a program in C to accept a grade and declare the equivalent description:
Grade Description

E Excellent
V Very Good

G Good

A Average

F Fail

7. Write separate programs for given following Physics formulas.

1. Write a program in C++ to make such a pattern like right angle triangle
with
number increased by 1.
Output Sample:
Enter a number: 4
1
23
456
7 8 9 10
Output Sample 2:
Enter a number: 6
1
23
456
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
2. Write a program in C++ to make such a pattern like a
pyramid with numbers increased by 1.
1
23
456
7 8 9 10
3. Write a program in C++ to display a diamond.
*
***
*****
*******
*********
*******
*****
***
*

4. Write a program to print Fibonacci series of n terms


where n is input by user:
0 1 1 2 3 5 8 13 24

5. Write a loop to find the factorial of any number.


Sample:
Enter number: 5
5! = 5 × 4 × 3 × 2 × 1 = 120

6. Write a program to calculate the sum of following series


where n is input by user.
1 + 1/2 + 1/3 + 1/4 + 1/5 +............1/n

7. Write a program that accepts three numbers from the user


and prints "increasing" if the numbers are in increasing
order, "decreasing" if the numbers are in decreasing
order, and "Neither increasing or decreasing order"
otherwise.
Sample:
Input first number: 1024
Input second number: 2645
Input third number: 4371
Expected Output:
Increasing order

8. Write a program to print following:

i)
**********
**********
**********
**********
ii)
*
**
***
****
*****
iii)
*
**
***
****
*****

iv)
*
***
*****
*******
*********
v)
1
222
33333
4444444
555555555

vi)
1
212
32123
4321234
543212345

You might also like