473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to find the length of the hypotenuse?

29
hello everyohow can we define a function hyptenuse that calculates the length of the hypotenuse of a right triangle when the other two sides are given. the function double hypotenuse(double, double); should be used to determine the length of the hypotenuse for each of the triangles shown below..

triangle side 1 side2
1 3.0 4.0
2 5.0 12.0
3 8.0 15.0
Jan 17 '07 #1
4 18351
Ganon11
3,652 Expert 2GB
OK. Are you having trouble with this? What have you tried so far? How will you solve this?
Jan 17 '07 #2
elsa
29
i was thinking of the program for the first triangle as the following:

#include<iostream>
using std::cout;
using std::endl;
//declaration of function
double hypotenuse (double,double);
int main()
{
cout<<"the hypotenuse of the first triangle is "<<hypotenuse<<endl;
return 0;
}

double hypotenuse(double x,double y)
{
x=3.0;
y=4.0;
hypotenuse=sqrt(x*x+y*y);
return hypotenuse;
}
but it is not working..there are alot of mistakes..
what can i do..plz help me solve my problems..
Jan 17 '07 #3
horace1
1,510 Expert 1GB
getting there - you main errors were failing the include the maths header file and the parameters to function hypotenuse()
updated code with comments where modifications have been made
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include <cmath>       // ** added
  3. using std::cout;
  4. using std::endl;
  5.  
  6. //declaration of function
  7. double hypotenuse (double,double);
  8. int main()
  9. {
  10. cout<<"the hypotenuse of the first triangle is "<<hypotenuse(3.0, 4.0) <<endl; // ** added parameters
  11. return 0;
  12. }
  13.  
  14. double hypotenuse(double x,double y)
  15. {
  16. //x=3.0; ** not required
  17. //y=4.0;
  18. double hypotenuse=sqrt(x*x+y*y);  //** added double
  19. return hypotenuse;
  20. }
  21.  
Jan 17 '07 #4
elsa
29
thx alot sir..ur tips helped me alot..
Jan 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
11
by: mailar | last post by:
Hi, I am using DB2 version 8.2 on Windows XP platform. I have a table 'EMP' with one field named 'NAME' of type CHAR , size 80. Also , I have a record with NAME='john' Now, when I try to...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
2
by: i33333 | last post by:
codes go here: // ----------------- start --------------------------- var s1 = ; var s2 = ; var s3 = ; var s4 = ; function addNum(arr) {
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
3
by: mouac01 | last post by:
Newbie here. How do I do a find and replace in a binary file? I need to read in a binary file then replace a string "ABC" with another string "XYZ" then write to a new file. Find string is the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.