need your help, i'm waiting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sala
    New Member
    • Nov 2006
    • 12

    need your help, i'm waiting

    I'm supposed to :
    1. Write a function “distance” that takes four arguments corresponding to the Cartesian Coordinates of two points (x1, y1) and (x2, y2), and returns the distance between the two points.
    - Call your function from a main program (write a complete program)
    - Your program should execute iteratively till a Sentinel value is types

    2. Write a function LCD (Least common divisor) that takes as input three integers, and returns the least common divisor of the three integers.
    - Call your function from a main program (write a complete program)
    - Your program should execute iteratively till a Sentinel value is types
  • vninja
    New Member
    • Oct 2006
    • 40

    #2
    returns the distance between the two points.
    Write a function “distance” that takes four arguments

    from these two parameters you know you have somthing like

    returntype functionname(ar g1, arg2, arg3, arg4)
    {
    since your finding the distance use the pythagorean therom from the difference of two of the four arguments
    return ans of formula
    }
    and i have no idea what you mean by
    - Your program should execute iteratively till a Sentinel value is types

    and for the second part do repeat the first but instead of the pythagorean therom used a formula for finding the LCD.
    Peace
    Vninja

    Comment

    • seeminsuleri
      New Member
      • Nov 2006
      • 9

      #3
      hey there,
      the first function would be something like the following code. but keep one thing in mind that the user will have to enter some ending value to denote the end of input and this has to be mentioned while taking the input from the user. This is called the Sentinel value. :)

      Code:
      #include <stdio.h>
      #include <conio.h>
      #include<math.h>
      using namespace std;
      
      float distance(float,float,float,float);
      void main()
      {
      float calculate,input1,input2,input3,input4;
      //take user inputs here,
      calculate=distance(input1,input2,input3,input4);
      cout<<calculate<<endl;
      return 0;
      }
      
      float distance(float input1,float input2,float input3,float input4)
      {
      float result,diff1,diff2,addition;
      diff1=input3-input1;
      diff2=input4-input2;
      diff1=diff1*diff1
      diff2=diff2*diff2;
      addition=diff1+diff2;
      result=sqrt(addition);
      return result;
      }
      Originally posted by sala
      I'm supposed to :
      1. Write a function “distance” that takes four arguments corresponding to the Cartesian Coordinates of two points (x1, y1) and (x2, y2), and returns the distance between the two points.
      - Call your function from a main program (write a complete program)
      - Your program should execute iteratively till a Sentinel value is types

      2. Write a function LCD (Least common divisor) that takes as input three integers, and returns the least common divisor of the three integers.
      - Call your function from a main program (write a complete program)
      - Your program should execute iteratively till a Sentinel value is types

      Comment

      Working...