Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Right Triangle Program

% cat rightTri.cpp
//Right triangle calculations

#include <iostream>
#include <cmath>
using namespace std;

int main()   // int is the return (data) type
{
   // variable declarations
  
   double leg_a, leg_b, hypotenuse, area;

   // get input values

   cout << "Enter leg a: ";
   cin >> leg_a;

   cout << "Enter leg b: ";
   cin >> leg_b;

   // computations

   area = 0.5 * leg_a *leg_b;
  
hypotenuse = sqrt( leg_a * leg_a  +  leg_b * leg_b );

   // display results

   cout << "Area = " << area << endl;
   cout << "Hypotenuse = " << hypotenuse << endl;

   return 0;

}
  
% g++ rightTri.cpp
% a.out
Enter leg a: 3.0
Enter leg b: 4.0
Area = 6
Hypotenuse = 5


 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming