Thread: Need Help To Calculate Hypotenuse Of Right Angles Triangle

  1. #1
    Registered User Hackstorix's Avatar
    Join Date
    Feb 2013
    Posts
    9

    Post 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. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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. #3
    Registered User Hackstorix's Avatar
    Join Date
    Feb 2013
    Posts
    9

    Post Thx

    Quote Originally Posted by Adak View Post
    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. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    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. #5
    Registered User Hackstorix's Avatar
    Join Date
    Feb 2013
    Posts
    9
    So how do i fix the program?

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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 subscribe to a feed

Similar Threads

  1. Calculating hypotenuse, missing remainder.
    By Blacklukes in forum C Programming
    Replies: 11
    Last Post: 06-28-2011, 03:44 PM
  2. Eular angles !!! Help
    By Andremaha in forum C Programming
    Replies: 2
    Last Post: 02-07-2011, 10:41 AM
  3. Replies: 7
    Last Post: 10-02-2010, 03:44 PM
  4. Hypotenuse Problem
    By dmkanz07 in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 10:07 AM