# Thread: Need Help To Calculate Hypotenuse Of Right Angles Triangle

1. ## Need Help To Calculate Hypotenuse Of Right Angles Triangle

Can Any Of You Help Correct This Code Please

Code:
```#include<stdio.h>
#include<conio.h>
#include<math.h>

void main(void)
{
int num1;
int num2;
int addsum;
double sum;

printf("Enter Opposite Side > ");
scanf("%d",&num1);
printf("Enter Adjacent Side > ");
scanf("%d",&num2);

num1 = num1 * num1;
num2 = num2 * num2;
addsum = num1 + num2;
sum = addsum;

if(addsum != 0){
sqrt(sum);
printf("The Hypotenuse Is %lf",sum);
}
getch();
}```

2. Line 26. sqrt() RETURNS the square root value, it doesn't change the number you give it for input.

You would help your program's clarity if you chose better variable names.

int a,b,Asquared, Bsquared, etc.

3. ## Thx

Originally Posted by Adak
Line 26. sqrt() RETURNS the square root value, it doesn't change the number you give it for input.

You would help your program's clarity if you chose better variable names.

int a,b,Asquared, Bsquared, etc.
How Do I change the number for the input

4. What Adak means is that sqrt() is a function which returns a value. You have to store this return value in a variable if you want to use it later in the program.

Currently you do nothing with it and that has the same effect as if you haven't called sqrt() at all.

Bye, Andreas

5. So how do i fix the program?

6. Catch the return from the function sqrt().

Code:
`sum=sqrt(sum);`
If you don't have a good help system on your IDE, I strongly suggest you get one, or bookmark one of the one's on the net. Google C reference for suggestions.

Looks like you're using turbo C, which has a GREAT help system, with small examples of every standard function. Why not use it?

Because this type of request, is not met with a great deal of cheer, from programmers. Responses will be rather blunt, before long.

Popular pages Recent additions