⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr0525.cpp

📁 practice c++, it is from the book http://www.amazon.com/Schaums-Outline-Programming-John-Hubbard
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Problem 5.25 on page 114
//  A Function that Computes Formulas for Triangles

#include <iostream>  // defines the cin and cout objects
using namespace std;
void computeTriangle(float& a, float& p, float x, float y, float z);

int main()
{ float a, p, x, y, z;
  cout << "Enter the sides: ";
  cin >> x >> y >> z;
  computeTriangle(a,p,x,y,z);
  cout << "The area of the triangle is " << a
       << "\nand its perimeter is " << p << endl;
}

void computeTriangle(float& a, float& p, float x, float y, float z)
{ p = x + y + z;
  float s = p/2.0;  // the semiperimeter of the triangle
  a = sqrt(s*(s-x)*(s-y)*(s-z));  // Heron's formula
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -