LearnFrenzy
Sign in Take a free test

Basic Syntax and Data Types · Exercise 4 of 4

Basic Syntax and Data Types Basic Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Beginner C++ programs on variables, data types, arithmetic and formatted output. Write each one yourself first, then open the solution – every solution was compiled and run, and the output shown is the real output.

Question 1 Easy

Swap two integers using a temporary variable, using std::swap, and using arithmetic without a temporary.

Question page & discussion
Question 2 Easy

Read a positive integer and print the sum of its digits and the number reversed.

Question page & discussion
Question 3 Easy

Convert a number of seconds to hours, minutes and seconds and print it as hh:mm:ss with leading zeros, for three test values.

Question page & discussion
Question 4 Medium

For a principal of ₹5,00,000 at 9% a year for 5 years, print the simple interest and the monthly EMI using the formula P·r·(1+r)n / ((1+r)n − 1).

Question page & discussion
Question 5 Easy

Write a function that tells whether a year is a leap year, and test it on 1900, 2000, 2024 and 2026.

Question page & discussion
Question 6 Easy

Print each character of the word "C++20" with its ASCII code, then convert lowercase letters of "LearnFrenzy" to uppercase using arithmetic on char.

Question page & discussion
Question 7 Medium

Using std::numeric_limits, print the size, minimum and maximum of short, int, long long and unsigned int.

Question page & discussion
Question 8 Easy

Read the number of subjects and the marks, then print the total, the average to two decimals and a grade (A ≥ 85, B ≥ 70, C ≥ 50, else F).

Question page & discussion
Question 9 Easy

Read a name, weight in kg and height in cm, then print the BMI to one decimal place and its category (Underweight < 18.5, Normal < 25, Overweight < 30, else Obese).

Question page & discussion
Question 10 Easy

Read expressions of the form a op b (integers) until the input ends and evaluate + − * / % with a switch, reporting division by zero.

Question page & discussion
All exercises doneBack to Basic Syntax and Data TypesRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links