Geometry
Finds a circle's area and solves a right triangle.
- Level
- Intermediate
- Topic:
- Math
- Concepts:
- Input & output
- Math
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
You use the PI constant, RC for square roots, and ATan, Sen and Cos for trigonometry. Trig functions work in radians, so you convert to degrees.
Code
Algoritmo Geometria Definir radio, cateto1, cateto2, hipotenusa, angulo Como Real Escribir "Radio del círculo:" Leer radio Escribir "Área: ", Redon(PI * radio ^ 2 * 100) / 100 Escribir "Perímetro: ", Redon(2 * PI * radio * 100) / 100 Escribir "Catetos de un triángulo rectángulo:" Leer cateto1, cateto2 hipotenusa <- RC(cateto1 ^ 2 + cateto2 ^ 2) // ATan devuelve radianes; los pasamos a grados angulo <- ATan(cateto1 / cateto2) * 180 / PI Escribir "Hipotenusa: ", hipotenusa Escribir "Ángulo opuesto al primer cateto: ", Redon(angulo), " grados" Escribir "Comprobación sen² + cos² = ", Sen(angulo * PI / 180) ^ 2 + Cos(angulo * PI / 180) ^ 2FinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Radio del círculo:User answer: 3Área: 28.27Perímetro: 18.85Catetos de un triángulo rectángulo:User answer: 3User answer: 4Hipotenusa: 5Ángulo opuesto al primer cateto: 37 gradosComprobación sen² + cos² = 1
Challenge
Also compute the triangle's area and perimeter.
Show hint
The area is cateto1 * cateto2 / 2 and the perimeter is the sum of the three sides.
Related examples
Prime Numbers
Finds every prime number up to a limit.
IntermediateGCD and LCM
Computes the greatest common divisor and the least common multiple.
IntermediateQuadratic Equation
Solves ax² + bx + c = 0, with real or complex roots.
Intermediate