Download presentation
Presentation is loading. Please wait.
1
C++ Basic Syntax – Homework Exercises
Write C++ code for solving the tasks on the following slides Code should compile under the C++03 or the C++11 standard Please submit only the .cpp files for these exercises Each exercise should be a separate .cpp file, named with the exercise number followed by what you feel describes the exercise in a few words E.g. a good name for exercise 2 of this homework would be 2.product-sign.cpp or 2.show-product-sign.cpp, 2.sign.cpp is also acceptable Don’t worry about the name too much, just make sure the number and the file extension are correct
2
Exercises Write a conditional statement that examines two integer variables and exchanges their values if the first one is greater than the second one. Write a program that shows the sign (+ or -) of the product of three real numbers without calculating it. Use a sequence of if statements. Write a program that enters the coefficients a, b and c of a quadratic equation a*x2 + b*x + c = 0 and calculates and prints its real roots. Note that quadratic equations may have 0, 1 or 2 real roots.
3
Exercises Write a program that prints all the numbers from 1 to N
Write a program that reads from the console a sequence of N integer numbers and returns the minimal and maximal of them Write a program that calculates the greatest common divisor (GCD) of given two numbers. Use the Euclidean algorithm (find it in Internet) Write a program that calculates for given N how many trailing zeros present at the end of the number N!. Examples N = 10, N! = , answer 2; N! = , answer: 4. Make sure your program works for N up to
4
Exercises Write a function that reverses the digits of given positive decimal number. Example: 256 652 Write a bool function that tests the function from task 8 with different values. It should call the function from 8 for a value and check the result against the expected answer. Make the function check at least 10 numbers of different length and return true if all were correct or false if any of them was wrong. Call that this checking function from main() and print it’s result For this task, you are NOT allowed to use any type of loop. Write a function that calculates the Nth Fibonacci number.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.