w3resource

C++ Basic: Exercises, Practice, Solution

C++ Basic [86 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a program in C++ to print welcome text on a separate line.
Click me to see the sample solution

2. Write a program in C++ to print the sum of two numbers.
Sample Output:
Print the sum of two numbers :
-----------------------------------
The sum of 29 and 30 is : 59
Click me to see the sample solution

3. Write a in C++ program to find the size of fundamental data types.
Sample Output:
Find Size of fundamental data types :
------------------------------------------
The sizeof(char) is : 1 bytes
The sizeof(short) is : 2 bytes
The sizeof(int) is : 4 bytes
The sizeof(long) is : 8 bytes
The sizeof(long long) is : 8 bytes
The sizeof(float) is : 4 bytes
The sizeof(double) is : 8 bytes
The sizeof(long double) is : 16 bytes
The sizeof(bool) is : 1 bytes
Click me to see the sample solution

4. Write a program in C++ to print the sum of two numbers using variables.
Print the sum of two numbers :
-----------------------------------
The sum of 29 and 30 is : 59
Click me to see the sample solution

5. Write a in C++ program to check the upper and lower limits of integers.
Expected Output:
Check the upper and lower limits of integer :
--------------------------------------------------
The maximum limit of int data type : 2147483647
The minimum limit of int data type : -2147483648
The maximum limit of unsigned int data type : 4294967295
The maximum limit of long long data type : 9223372036854775807
The minimum limit of long long data type : -9223372036854775808
The maximum limit of unsigned long long data type : 18446744073709551615
The Bits contain in char data type : 8
The maximum limit of char data type : 127
The minimum limit of char data type : -128
The maximum limit of signed char data type : 127
The minimum limit of signed char data type : -128
The maximum limit of unsigned char data type : 255
The minimum limit of short data type : -32768
The maximum limit of short data type : 32767
The maximum limit of unsigned short data type : 65535
Click me to see the sample solution

6. Write a C++ program that checks whether primitive values cross the limit.
Check whether the primitive values crossing the limits or not :
--------------------------------------------------------------------
The Gender is : F
Is she married? : 1
Number of sons she has : 2
Year of her appointment : 2009
Salary for a year : 1500000
Height is : 79.48
GPA is 4.69
Salary drawn upto : 12047235
Balance till : 995324987
Click me to see the sample solution

7. Write a C++ program that displays mixed data types and arithmetic operations.
Sample output:
Display arithmetic operations with mixed data type :
---------------------------------------------------------
5 + 7 = 12
3.7 + 8.0 = 11.7
5 + 8.0 = 13.0
5 - 7 = -2
3.7 - 8.0 = -4.3
5 - 8.0 = -3.0
5 * 7 = 35
3.7 * 8.0 = 29.6
5 * 8.0 = 40.0
5 / 7 = 0
3.7 / 8.0 = 0.5
5 / 8.0 = 0.6
Click me to see the sample solution

8. Write a C++ program to check overflow/underflow during various arithmetic operations.
Sample Output:
Check overflow/underflow during various arithmetical operation :
Range of int is [-2147483648, 2147483647]
---------------------------------------------------------------------
Overflow the integer range and set in minimum range : -2147483648
Increasing from its minimum range : -2147483647
Product is :1
Underflow the range and set in maximum range : 2147483647
Decreasing from its maximum range : 2147483646
Product is : 0
Click me to see the sample solution

9. Write a C++ program to display the operation of pre and post increment and decrement.
Sample Output:
Display the operation of pre and post increment and decrement :
--------------------------------------------------------------------
The number is : 57
After post increment by 1 the number is : 58
After pre increment by 1 the number is : 59
After increasing by 1 the number is : 60
After post decrement by 1 the number is : 59
After pre decrement by 1 the number is : 58
After decreasing by 1 the number is : 57
Click me to see the sample solution

10. Write a C++ program to format the output.
Sample Output:
Formatting the output :
----------------------------
The value of pi : 3.1416
The value of pi 4 decimal place of total width 8 : | 3.1416|
The value of pi 4 decimal place of total width 10 : | 3.1416|
The value of pi 4 decimal place of total width 8 : |--3.1416|
The value of pi 4 decimal place of total width 10 : |----3.1416|
The value of pi in scientific format is : 3.1416e+00
Status in number : 0
Status in alphabet : false
Click me to see the sample solution

11. Write a C++ program to print the results of the specified operations.
Sample Output:
Print the result of some specific operation :
--------------------------------------------------
Result of 1st expression is : 23
Result of 2nd expression is : 5
Result of 3rd expression is : 12
Result of 4th expression is : 3
Click me to see the sample solution

12. Write a C++ program to add two numbers and accept them from the keyboard.
Sample Output:
Sum of two numbers :
-------------------------
Input 1st number : 25
Input 2nd number : 39
The sum of the numbers is : 64
Click me to see the sample solution

13. Write a C++ program that swaps two numbers.
Sample Output:
Swap two numbers :
-----------------------
Input 1st number : 25
Input 2nd number : 39
After swapping the 1st number is : 39
After swapping the 2nd number is : 25
Click me to see the sample solution

14. Write a C++ program that calculates the volume of a sphere.
Sample Output:
Calculate the volume of a sphere :
---------------------------------------
Input the radius of a sphere : 6
The volume of a sphere is : 904.32
Click me to see the sample solution

15. Write a C++ program that calculates the volume of a cube.
Sample Output:
Calculate the volume of a cube :
---------------------------------------
Input the side of a cube : 5
The volume of a cube is : 125
Click me to see the sample solution

16. Write a C++ program that calculates the volume of a cylinder.
Sample Output:
Calculate the volume of a cylinder :
-----------------------------------------
Input the radius of the cylinder : 6
Input the height of the cylinder : 8
The volume of a cylinder is : 904.32
Click me to see the sample solution

17. Write a C++ program to find the Area and Perimeter of a Rectangle.
Sample Output:
Find the Area and Perimeter of a Rectangle :
-------------------------------------------------
Input the length of the rectangle : 10
Input the width of the rectangle : 15
The area of the rectangle is : 150
The perimeter of the rectangle is : 50
Click me to see the sample solution

18. Write a C++ program to find the area of any triangle using Heron's formula.
Sample Output:
Find the area of any triangle using Heron's Formula :
----------------------------------------------------------
Input the length of 1st side of the triangle : 5
Input the length of 2nd side of the triangle : 5
Input the length of 3rd side of the triangle : 5
The area of the triangle is : 10.8253
Click me to see the sample solution

19. Write a C++ program to find the area and circumference of a circle.
Sample Output:
Find the area and circumference of any circle :
----------------------------------------------------
Input the radius(1/2 of diameter) of a circle : 5
The area of the circle is : 78.5397
The circumference of the circle is : 31.4159
Click me to see the sample solution

20. Write a C++ program to convert temperature in Celsius to Fahrenheit.
Sample Output:
Convert temperature in Celsius to Fahrenheit :
---------------------------------------------------
Input the temperature in Celsius : 35
The temperature in Celsius : 35
The temperature in Fahrenheit : 95
Click me to see the sample solution

21. Write a C++ program to convert temperature in Fahrenheit to Celsius.
Sample Output:
Convert temperature in Fahrenheit to Celsius :
---------------------------------------------------
Input the temperature in Fahrenheit : 95
The temperature in Fahrenheit : 95
The temperature in Celsius : 35
Click me to see the sample solution

22. Write a C++ program to find the third angle of a triangle.
Sample Output:
Find the third angle of a triangle :
-----------------------------------------
Input the 1st angle of the triangle : 30
Input the 2nd angle of the triangle : 60
The 3rd of the triangle is : 90
Click me to see the sample solution

23. Write a program in C++ that converts kilometers per hour to miles per hour.
Sample Output:
Convert kilometers per hour to miles per hour :
----------------------------------------------------
Input the distance in kilometer : 25
The 25 Km./hr. means 15.5343 Miles/hr.
Click me to see the sample solution

24. Write a program in C++ to convert temperature in Kelvin to Fahrenheit.
Sample Output:
Convert temperature in Kelvin to Fahrenheit :
---------------------------------------------------
Input the temperature in Kelvin : 300
The temperature in Kelvin : 300
The temperature in Fahrenheit : 80.33
Click me to see the sample solution

25. Write a program in C++ to convert temperature in Kelvin to Celsius.
Sample Output:
Convert temperature in Kelvin to Celsius :
------------------------------------------------
Input the temperature in Kelvin : 300
The temperature in Kelvin : 300
The temperature in Celsius : 26.85

Click me to see the sample solution

26. Write a program in C++ to convert temperature in Fahrenheit to Kelvin.
Sample Output:
Convert temperature in Fahrenheit to Kelvin :
---------------------------------------------------
Input the temperature in Fahrenheit : 80.33
The temperature in Fahrenheit : 80.33
The temperature in Kelvin : 300
Click me to see the sample solution

27. Write a program in C++ to convert temperature in Celsius to Kelvin.
Sample Output:
Convert temperature in Celsius to Kelvin :
---------------------------------------------------
Input the temperature in Celsius : 26.85
The temperature in Celsius : 26.85
The temperature in Kelvin : 300
Click me to see the sample solution

28. Write a C++ program to find the area of the Scalene Triangle.
Sample Output:
Find the area of Scalene Triangle :
----------------------------------------
Input the length of a side of the triangle : 5
Input the length of another side of the triangle : 6
Input the angle between these sides of the triangle : 6
The area of the Scalene Triangle is : 1.56793
Click me to see the sample solution

29. Write a C++ program to compute the quotient and remainder.
Sample Output:
Compute quotient and remainder :
-------------------------------------
Input the dividend : 25
Input the divisor : 3
The quotient of the division is : 8
The remainder of the division is : 1
Click me to see the sample solution

30. Write a C++ program to compute the total and average of four numbers.
Sample Output:
Compute the total and average of four numbers :
----------------------------------------------------
Input 1st two numbers (separated by space) : 25 20
Input last two numbers (separated by space) : 15 25
The total of four numbers is : 85
The average of four numbers is : 21.25
Click me to see the sample solution

31. Write a C++ program to input a single-digit number and print it in a rectangular form of 4 columns and 6 rows.
Sample Output:
Make a rectangular shape by a single digit number :
--------------------------------------------------------
Input the number : 5
5555
5 5
5 5
5 5
5 5
5555
Click me to see the sample solution

32. Write a program in C++ to check whether a number is positive, negative or zero.
Sample Output:
Check whether a number is positive, negative or zero :
-----------------------------------------------------------
Input a number : 8
The entered number is positive.
Click me to see the sample solution

33. Write a program in C++ to divide two numbers and print them on the screen.
Sample Output:
Divide two numbers and print:
----------------------------------
The quotient of 30 and 10 is : 3
Click me to see the sample solution

34. Write a C++ program to display the current date and time.
Sample Output:
Display the Current Date and Time :
----------------------------------------
seconds = 57
minutes = 33
hours = 12
day of month = 6
month of year = 7
year = 2017
weekday = 4
day of year = 186
daylight savings = 0
Current Date: 6/7/2017
Current Time: 12:33:57
Click me to see the sample solution

35. Write a program in C++ to compute the specified expressions and print the output.
Sample Output:
Compute the specified expressions and print the output:
------------------------------------------------------------
Result of the expression (25.5 * 3.5 - 3.5 * 3.5) / (40.5 - 4.5) is : 2.13889
Click me to see the sample solution

36. Write a program in C++ to test Type Casting.
Sample Output:
Formatting the output using type casting:
----------------------------------------------
Print floating-point number in fixed format with 1 decimal place:
Test explicit type casting :
0
0.5
0.5
0.0
Test implicit type casting :
0
0
int implicitly casts to double:
4.0
double truncates to int!:
6
Click me to see the sample solution

37. Write a C++ program to print a mystery series from 1 to 50.
Sample Output:
Print a mystery series:
-------------------------
The series are:
5 4 2 7 11 10 8 13 17 16 14 19 23 22 20 25 29 28 26 31 35 34 32 37 41 4 0 38 43 47 46 44 49
Click me to see the sample solution

38. Write a C++ program that takes a number as input and prints its multiplication table up to 10.
Sample Output:
Print the multiplication table of a number upto 10:
--------------------------------------------------------
Input a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Click me to see the sample solution

39. Write a C++ program to print the following pattern.
Sample Output:

 xxxxx                                                                                                        
x     x       x        x                                                                                      
x             x        x                                                                                      
x          xxxxxxx  xxxxxxx                                                                                   
x             x        x                                                                                      
x     x       x        x                                                                                      
 xxxxx  

Click me to see the sample solution

40. Write a C++ program to print the area and perimeter of a rectangle.
Sample Output:
Print the area and perimeter of a rectangle:
----------------------------------------------
Input the width of the rectangle: 8.5
Input the height of the rectangle: 5.6
The area of the rectangle is: 47.6
The perimeter of the rectangle is: 28.2
Click me to see the sample solution

41. Write a C++ program to print an American flag on the screen.
Sample Output:

 Print the American flag:                                              
-----------------------------                                          
* * * * * * ==================================                         
 * * * * *  ==================================                         
* * * * * * ==================================                         
 * * * * *  ==================================                         
* * * * * * ==================================                         
 * * * * *  ==================================                         
* * * * * * ==================================                         
 * * * * *  ==================================                         
* * * * * * ==================================                         
==============================================                         
==============================================                         
==============================================                         
==============================================                         
==============================================                         
==============================================
Click me to see the sample solution

42. Write a C++ program that accepts the user's first and last name and prints them in reverse order with a space between them.
Sample Output:
Print the name in reverse where last name comes first:
-----------------------------------------------------------
Input First Name: Alexandra
Input Last Name: Abramov
Name in reverse is: Abramov Alexandra
Click me to see the sample solution

43. Write a C++ program that accepts the radius of a circle from the user and computes the area and circumference.
Sample Output:
Find the area and circumference of any circle :
----------------------------------------------------
Input the radius(1/2 of diameter) of a circle : 5
The area of the circle is : 78.5397
The circumference of the circle is : 31.4159
Click me to see the sample solution

44. Write a C++ program to get the volume of a sphere with radius 6.
Sample Output:
Calculate the volume of a sphere :
---------------------------------------
Input the radius of a sphere : 5
The volume of a sphere is : 523.333
Click me to see the sample solution

45. Write a C++ program to calculate the volume of a cone.
Sample Input: 5 3
Sample Output:
Input Cone's radius: Input Cone's height: The volume of the cone is: 78.5397
Click me to see the sample solution

46. Write a C++ program to calculate the volume of a cylinder.
Sample Output:
Calculate the volume of a cylinder :
-----------------------------------------
Input the radius of the cylinder : 4
Input the height of the cylinder : 8
The volume of a cylinder is : 401.92
Click me to see the sample solution

47. Write a C++ program to calculate the sum of all even and odd numbers in an array.
Sample Output:
Original array: 1 2 3 4 5 6 7 8
Sum of all even and odd numbers: 20,16
Click me to see the sample solution

48. Write a C++ program that swaps two variables without using a third variable.
Sample Output:
Swap two numbers without using third variable:
---------------------------------------------------
Input 1st number : 25
Input 2nd number : 20
After swapping the 1st number is : 20
After swapping the 2nd number is : 25
Click me to see the sample solution

49. Write a C++ program to print the code (ASCII code / Unicode code etc.) of a given character.
Sample Output:
Print code (ASCII code / Unicode code etc.) of a given character:
-----------------------------------------------------------------------
Input a character: a
The ASCII value of a is: 97
The character for the ASCII value 97 is: a
Click me to see the sample solution

50. Write a C++ program to enter length in centimeters and convert it into meters and kilometers.
Sample Output:
Convert centimeter into meter and kilometer :
--------------------------------------------------
Input the distance in centimeter : 250000
The distance in meter is: 2500
The distance in kilometer is: 2.5
Click me to see the sample solution

51. Write a C++ program that converts kilometers per hour to miles per hour.
Sample Output:
Convert kilometers per hour to miles per hour :
----------------------------------------------------
Input the distance in kilometer : 5
The 5 Km./hr. means 3.10686 Miles/hr.
Click me to see the sample solution

52. Write a C++ program to enter two angles of a triangle and find the third angle.
Sample Output:
Find the third angle of a triangle :
-----------------------------------------
Input the 1st angle of the triangle : 35
Input the 2nd angle of the triangle : 35
The 3rd of the triangle is : 110
Click me to see the sample solution

53. Write a C++ program to calculate the area of an equilateral triangle.
Sample Output:
Calculate the area of the Equilateral Triangle :
----------------------------------------------------
Input the value of the side of the equilateral triangle: 5
The area of equilateral triangle is: 10.8253
Click me to see the sample solution

54. Write a C++ program to enter P, T, R and calculate Simple Interest.
Sample Output:
Calculate the Simple Interest :
-----------------------------------
Input the Principle: 20000
Input the Rate of Interest: 10
Input the Time: 1.5
The Simple interest for the amount 20000 for 1 years @ 10 % is: 2000
Click me to see the sample solution

55. Write a C++ program to enter P, T, R and calculate compound interest.
Sample Output:
Calculate the Compound Interest :
------------------------------------- Input the Principle: 20000
Input the Rate of Interest: 10
Input the Time: 1.5
The Interest after compounded for the amount 20000 for 1.5 years @ 10
% is: 3073.8 The total amount after compounded for the amount 20000 for 1.5 years @
10 % is: 23073.8
Click me to see the sample solution

56. Write a C++ program to show the manipulation of a string.
Sample Output:
Show the manipulation of a string:
-------------------------------------
The string:: welcome, w3resource
The length of the string:: 19
The char at index 1 of the string:: e
The char at index 1 of the string [using array ]:: e
Is the string empty:: 0
Retrieve the sub-string from 3rd position for 4 characters:: come
The sub-string replace by 'went':: welwent, w3resource
Append a string 'end' at last of the string:: welwent, w3resource end
Append a string 'end' at last of the string using operator:: welwent, w3resource end end
The string 'insert' inserting at 3rd position of the string:: wel inse rt went, w3resource end
The new string is:: wel insert went, w3resource end
Input a sentence:: The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
Click me to see the sample solution

57. Write a C++ program to print the area of a hexagon.
Sample Output:
Print the area of a hexagon:
---------------------------------
Input the side of the hexagon: 6
The area of the hexagon is: 93.5307
Click me to see the sample solution

58. Write a C++ program to print the area of a polygon.
Sample Output:
Print the area of a polygon:
---------------------------------
Input the number of sides of the polygon: 7
Input the length of each side of the polygon: 6
The area of the polygon is: 130.821
Click me to see the sample solution

59. Write a C++ program to compute the distance between two points on the surface of the earth.
Sample Output:
Print the the distance between two points on the surface of earth:
-----------------------------------------------------------------------
Input the latitude of coordinate 1: 25
Input the longitude of coordinate 1: 35
Input the latitude of coordinate 2: 35.5
Input the longitude of coordinate 2: 25.5
The distance between those points is: 1480.08
Click me to see the sample solution

60. Write a C++ program to add two binary numbers.
Sample Output:
Addition of two binary numbers:
-----------------------------------
Input the 1st binary number: 1010
Input the 2nd binary number: 0011
The sum of two binary numbers is: 1101
Click me to see the sample solution

61. Write a C++ program to swap the first and last digits of any number.
Sample Output:
Input any number: 12345
The number after swapping the first and last digits are: 52341
Click me to see the sample solution

62. Write a C++ program that reads the integer n and prints a twin prime that has the maximum size among twin primes less than or equal to n.
According to wikipedia "A twin prime is a prime number that is either 2 less or 2 more than another prime number" for example, either member of the twin prime pair (41, 43). In other words, a twin prime is a prime that has a prime gap of two".
Click me to see the sample solution

63. Write a C++ program that prints the three highest numbers from a list of numbers in descending order.
Click me to see the sample solution

64. Write a C++ program to compute the sum of the two given integers and count the number of digits in the sum value.
Click me to see the sample solution

65. Write a C++ program to check whether a given length of three sides forms a right triangle.
Click me to see the sample solution

66. Write a C++ program to add all the numbers from 1 to a given number.
Add 1 to 4: 10
Add 1 to 100: 5050
Click me to see the sample solution

67. Write a C++ program that prints the central coordinate and the radius of a circumscribed circle of a triangle. This circle is created from three points on the plane surface.
Click me to see the sample solution

68. Write a C++ program that reads seven numbers and sorts them in descending order.
Click me to see the sample solution

69. For n = 10, write a C++ program that reads the integer n and prints its factorial.
Click me to see the sample solution

70. Write a C++ program to replace all the lower-case letters in a given string with the corresponding capital letters.
Click me to see the sample solution

71. Write a C++ program that reads a sequence of integers and prints the mode values of the sequence. The number of integers is greater than or equal to 1 and less than or equal to 100.
Note: The mode of a set of data values is the value that appears most often.
Click me to see the sample solution

72. Write a C++ program that reads n digits chosen from 0 to 9 and counts the number of combinations where the sum of the digits equals the given number. Do not use the same digits in a combination.
For example, the combinations where n = 2 and s = 5 are as follows:
0 + 5 = 5
1 + 4 = 5
3 + 2 = 5
Click me to see the sample solution

73. Write a C++ program that accepts the sales unit price and sales quantity of various items and computes the total sales amount and the average sales quantity. All input values must be greater than or equal to 0 and less than or equal to 1,000. In addition, the number of pairs of sales unit and sales quantity does not exceed 100. If a fraction occurs in the average of the sales quantity, round to the first decimal place.
Click me to see the sample solution

74. Write a C++ program that accepts various numbers and computes the difference between the highest number and the lowest number. All input numbers should be real numbers between 0 and 1,000,000. The output (real numbers) may include an error of 0.01 or less.
Click me to see the sample solution

75. Write a C++ program to compute the sum of the specified number of prime numbers.
For example when n = 7,
s = 2 + 3 + 5 + 7 + 11 + 13 + 17 = 58.
Click me to see the sample solution

76. An even number of 4 or more can be represented by the sum of two prime numbers. This is called the Goldbach expectation, and it is confirmed that it is correct up to a considerable number by computer calculation. For example, 10 can be expressed as the sum of two prime numbers 7 + 3, 5 + 5. Write a C++ program that accepts an integer (n) from the user and outputs the number of combinations that express n as the sum of two prime numbers.
Note: n should be greater than or equal to 4 and less than or equal to 50,000.
Click me to see the sample solution

77. There are four different points on a plane: A(x1, y1), B(x2, y2), C(x3, y3) and D(x4, y4).
Write a C++ program to check whether two straight lines AB and CD are orthogonal or not.
Input:
0 6
5 6
3 8
3 2
Output:
yes
Click me to see the sample solution

78. Write a C++ program to sum all positive integers in a sentence.
Sample string: There are 12 chairs, 15 desks, 1 blackboard and 2 fans.
Output: 30
Click me to see the sample solution

79. Write a C++ program to display all the leap years between two given years. If there is no leap year in the given period,display a suitable message.
Note: Range of the two given years: ( 0 < year1 = year2 < 3,000).
Click me to see the sample solution

80. Write a C++ program that accepts n different numbers (0 to 100) as well as an integer s which is equal to the sum of the n different numbers.
Your job is to find the number of combinations of n numbers and the same number cannot be used for one combination.
Click me to see the sample solution

81. Write a C++ program that replaces all the words "dog" with "cat".
Sample Text: The quick brown fox jumps over the lazy dog. You can assume that the number of characters in a text is less than or equal to 1000.
Click me to see the sample solution

82. Write a C++ program that reads a list of pairs of a word and a page number, and prints the word and a list of the corresponding page numbers.
Click me to see the sample solution

83. Write a C++ program to convert a given number into hours and minutes. Separate the number of hours and minutes with a colon.
For example if a given number is 67 the output should be 1:7
Click me to see the sample solution

84. Write a C++ program to check whether the sequence of the numbers in a given array is an "Arithmetic" or "Geometric" sequence. Return -1 if the sequence is not "Arithmetic" or "Geometric".
From Wikipedia
In mathematics, an arithmetic progression (AP) or arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. Difference here means the second minus the first. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with common difference of 2.
In mathematics, a geometric progression, also known as a geometric sequence, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.
Example:
Sample Input: int nums1[] = { 1, 3, 5, 7 }
Sample Output: Arithmetic sequence
Click me to see the sample solution

85. Write a C++ program to find the total number of minutes between two given times (formatted with a colon and am or pm).
Example:
Sample Input: Minutes between 12:01AM to 12:00PM:
Sample Output: Minutes between 12:01AM to 12:00PM: 1439
Click me to see the sample solution

86. Write a C++ program to add up all the digits between two given integers. Add all the digits between 11 and 16.
Example:
Add up all the digits between 39 and 41 is: 21
Click me to see the sample solution

CPP Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/cpp-exercises/basic/index.php