C++ Conditional Statements Exercises

Guys, let's wrap up a section of our C ++ course once again.
Congratulations if you arrived here. Now let's practice our knowledge by doing some exercises.

And remember, try hard, but really, really hard.
Not of? Think some more. Then more, take a walk, cool your head, and try again.

Problem solving is synonymous with being a programmer, so try to solve the exercises below using your basic knowledge of C ++ and conditional testing.

C++ conditional testing problems

01. Make a program that asks for two numbers, and say which one is larger or if they are equal.
How to compare two numbers in C++

02. Write a program that tells you whether a received number is positive or negative.

03. Make a program that asks for two integers and store in two variables. Then change the value of the variables and display on screen
Swapping two numbers

04. Make a program that asks for 3 numbers and places them in ascending order.

05. Make a program that asks for 3 numbers and puts them in descending order.
3 numbers in ascending and descending order

06. Program software that receives the user's X and Y coordinates, and tell which quadrant the point is in.

07. Make a simple calculator program that asks the user for two numbers, then displays a menu where he will choose which operation to perform. The operation and output must be in a switch case.

08. Using switch case concepts, make a program that asks the user the month (number 1 through 12), and tells you how many days that month has. February is 28 days old (not leap).

09. Using switch case concepts, make a program that asks the user the month (number 1 through 12), and tells you how many days that month has, including whether it is a leap year or not.
How many days a month has

10. Make a program that takes all three sides of a triangle and tells you if it is equilateral, isosceles, or scalene.
Types of triangle

11. Make a program that calculates the roots of a quadratic equation in the form ax² + bx + c. The program should request the values ​​of a, b and c and make the calculations, informing the user in the following situations:

    If the user enters the value of A equal to zero, the equation is not of the second degree and the program should not ask the other values, being closed;
    If the calculated delta is negative, the equation has no real roots. Inform the user and quit the program;
    If the calculated delta equals zero the equation has only one real root; inform it to the user;
    If delta is positive, the equation has two real roots; inform them to the user;

PS: Use cmath library (#include <cmath>) and sqrt(x) function to calculate the square root of x.

How to solve quadratic equation in C++

No comments:

Post a Comment