C
exercises
- Write the program OUT3.CPP, that shows a square root numbers table of the
integer numbers in the range from 2 to 10. You may use the header file
MATH.H to import the sqrt() function, it returns the root square from a
double type argument. Use the format %3.01f i %3.41f control to show the
numbers and its square roots respectively.
- Write the program IF5.CPP to solve the quadratic equation roots. The
quadratic equation is :
A*x^2 + B*x + C = 0
The quadratic equation roots are :
Root1 = ( -B + sqrt( B^2 – 4*A*C ) ) / ( 2* A)
Root2 = ( -B - sqrt( B^2 – 4*A*C ) ) / ( 2* A)
If the square root term is negative, the roots are
complex. If the square root term is zero, the two square roots are the same and
they are equal to : -B / (2*A)
- Write the program SWITCH2.CPP to implement a four functions single calculator.
The program should ask for the numbers and the function (+,-,* or /) and
should show the operation and the solution. You may include the errors
handling for the "by zero division".
- Write the program FOR5.CPP, that uses a loop ("for" type) to get
and show the sum of all the odd numbers in the range from 11 to 121.
- Write the program WHILE2.CPP, that uses a loop ("while" type) to
get and show the sum of all the odd numbers squared in the range from 11
to 121.
- Write the program DOWHILE2.CPP, that uses a loop
("do-while" type) to get and show the sum of all the odd numbers
squared in the range from 11 to 121.
- Write the program ARRAY1.CPP, that will be used to calculate the average
temperature of n towns. First of all, the program asks how many towns you
want to work with (n). Then it asks every value of the temperatures
(temp[i]=_ ) , been i a number between 0 and n-1. Finally the program
calculates the average temperature and displays it. Supose a maximum
number of 20 towns.
- Write the program ARRAY2.CPP, that will be used to calculate the average
temperature of n towns all the week. The algorithm is similar to the
exercise 7, with the difference of using a bidimensional array, one
dimension for the days of the week (7 days) and the other for the towns. The
way to ask the temperatures will be : temp[i][j]=_, been i a number in the
range from 0 to n-1 (town number) and j goes between 1 and 7 (weekday). In
other way, it asks first temp[0][1], after temp[0][2] ... until arrives to
temp[0][7] and after asks temp[1][0]... until arrives to temp[n-1][7]. At
last the program shows the weekly average of the towns.
- To implement writeFile.cpp that generates "trial.txt"
file. This program should write a string in the file.
- To implement readFile.cpp
that reads "trial.txt"
http://www.binefa.net/