Simple C++ Programs
• Write a program that prints a text of 4 lines consisting of characters, integer values, floating-
point and string using cout statement.
• Write a program that asks the user to type 5 integers and writes the average of the 5 integers.
• Write a program that inputs the radius of the sphere from the user. Calculates its area using
the formula Area = 4∏R2 and circumference = 4/3∏R3 where it=3.14.
• Write a program to find out the area of triangle when three sides a, b and c of the triangle are
given. Use appropriate statements to input the values of a, b and c from the keyboard.
Formula for the area of triangle is
Where0020s = (a + b + c) / 2.
• Write a program that inputs a number from user and displays its square and cube.
• A car can travel 5.3 miles in 1 liter. Write a program that inputs petrol in liters and displays
how much distance the car can cover using the available petrol.
• Write a program that inputs total number of student in a class and fee per student. It displays
total fee collected from the class.
• Write a program that asks the user to accept amount and discount from the user then display
the payed amount.
HINT:
dis_amonut= (discont/100)*amount
• Accept two entry and then display arithmetic operation (+,-,*, /, %).
• Accept the values in meter then display in inches and centimeters.
HINT:
1m = 39.370079 inches
1 meter (m) = 100 centimeters (cm)
• Accept the values in GB and display the value in bytes.
HINT:
1 GB=1024*1024*1024 bytes
• Write a program that asks the user to type the width and the length of a rectangle and then
outputs to the screen the area and the perimeter of that rectangle
HINT:
area=width*length
perimeter=2*(width+length)
• Write a program which accept temperature in Fahrenheit and print it in centigrade
HINT:
5*(F-32)/9
• Write a program to swap the values of two variables
• Write a program to swap value of two variables without using third variable
• What is the output of following program?
• int result = 4 + 5 * 6 + 2;
cout<<result;
• int result = 5 - 3 * 4 % (6 – 2 $ 2);
cout<<result;
• int a = 5 + 7 % 2;
cout<<a;
• int no = 2;
int result = ++no*2 - 12;
cout<<result<<endl;
cout<<no<<endl;
• int no = 2;
int result = ++no - no++ * 2;
cout<<result<<endl;
• Write the following formula into C++ executable statement.
• int x= 20, y = 35;
x = y++ + x++;
y = ++y + x++;
• Write a program which accepts a character and display its next character.
• Write a progra m
which accepts days as integer and display total number of years, months and days in it.
For example: If user input as 856 days the output should be 2 years 4 months 6 days.
• Accept 5 digits no from the user then display following option.
No=12345
Result =15
• Write a program that display the following output using single cout statement.
1 2 3 4 5
6 7 8 9 10
• Write a program that inputs the x, y coordinates for two points and computes distance
between two points using the formula: Distance = sqrt (x2 – x1)2 + (y2 - y1)2.
• Write a program that inputs the name, Basic Salary of the employee. The program calculates
35% dearness allowance, 25% house rent of the employee from the basic salary then displays
the gross salary which is adds basic salary, dearness allowance and house rent of the
employee.
• Write a program that inputs principal amount, rate of interest and total time. It calculates the
compound interest and displays it.