Skip to content
ExamplesEspañolWorkspace →

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

geometry.psc · 15 lines
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) ^ 2FinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo GeometriaAlgoritmo GeometriaAlgoritmo GeometriaDefinir radio, cateto1, cateto2, hipotenusa, angulo Como RealDefinir radio, cateto1,cateto2, hipotenusa, anguloComo RealEscribir "Radio del círculo:"Escribir "Radio del círculo:"Leer radioLeer radioEscribir "Área: ", Redon(PI() * radio ^ 2 * 100) / 100Escribir "Área: ", Redon(PI()* radio ^ 2 * 100) / 100Escribir "Perímetro: ", Redon(2 * PI() * radio * 100) / 100Escribir "Perímetro: ",Redon(2 * PI() * radio * 100)/ 100Escribir "Catetos de un triángulo rectángulo:"Escribir "Catetos de untriángulo rectángulo:"Leer cateto1, cateto2Leer cateto1, cateto2hipotenusa <- RC(cateto1 ^ 2 + cateto2 ^ 2)hipotenusa <- RC(cateto1 ^ 2 +cateto2 ^ 2)angulo <- ATan(cateto1 / cateto2) * 180 / PI()angulo <- ATan(cateto1 /cateto2) * 180 / PI()Escribir "Hipotenusa: ", hipotenusaEscribir "Hipotenusa: ",hipotenusaEscribir "Ángulo opuesto al primer cateto: ", Redon(angulo), " grados"Escribir "Ángulo opuesto alprimer cateto: ",Redon(angulo), " grados"Escribir "Comprobación sen² + cos² = ", Sen(angulo * PI() / 180) ^ 2 + Cos(angulo * PI() / 180) ^ 2Escribir "Comprobación sen² +cos² = ", Sen(angulo * PI() /180) ^ 2 + Cos(angulo * PI()…FinAlgoritmoFinAlgoritmo

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.

Open in Codoritmo
  • Prime Numbers

    Finds every prime number up to a limit.

    Intermediate
  • GCD and LCM

    Computes the greatest common divisor and the least common multiple.

    Intermediate
  • Quadratic Equation

    Solves ax² + bx + c = 0, with real or complex roots.

    Intermediate