Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
I am a beginning programmer and have been asked to create a program that asks the user to give length for a hypotenuse of a Triangle and the program is supposes to assume that the Triangle is a 30,60,90 degree triangle (right triangle) and give the other two sides.

I was given that side a=hyp*Cos(30) and b=hyp*Sin(30). Im just not sure how to use the math library functions in C. Here is my code so far:


C++
{
float hypotenuse;

printf("Enter the length of the hypotenuse:");
scanf("%f", &hypotenuse);
printf("You have entered that the hypotenuse=%9.2f\n",hypotenuse);
}
Posted
Updated 11-Jun-14 23:31pm
v2
Comments
Sergey Alexandrovich Kryukov 11-Jun-14 17:02pm    
Knowing of elementary middle-school mathematics should be considered as a prerequisite of programming. How ab out not being "given that", but actually doing elementary calculation by yourself?
Another question: why using C, not C++?
And finally, what prevents you from searching the available libraries and original documentation for such a basic thing? You could get an answer faster then posting this question.
—SA

Please see my comments to the question and try to become at least a bit more independent. So far, you are not in a minimal working shape. :-)

With C, you can use "math.h":
http://www.techonthenet.com/c_language/standard_library_functions/math_h/cos.php[^],
http://www.techonthenet.com/c_language/standard_library_functions/math_h/sin.php[^].

With C++ and "tmath.h", you could have type-generic macro version of the functions:
http://www.cplusplus.com/reference/cmath/cos[^],
http://www.cplusplus.com/reference/cmath/sin/[^].

—SA
 
Share this answer
 
Comments
CPallini 12-Jun-14 5:38am    
5.
You'd probably want to start here [^]

Got that by Googling C# trig functions.
 
Share this answer
 
Comments
Matt T Heffron 11-Jun-14 19:32pm    
C not C#
Actually you didn't even need trigonometric functions. Your right triangle is exactly the half on an equilater one. So a is really simple to know while you just need sqrt to findo out b.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900