By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

need your help, i'm waiting

P: 12
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
Nov 5 '06 #1
Share this Question
Share on Google+
2 Replies


vninja
P: 40
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(arg1, 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
Nov 6 '06 #2

seeminsuleri
P: 9
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. :)

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include<math.h>
  5. using namespace std;
  6.  
  7. float distance(float,float,float,float);
  8. void main()
  9. {
  10. float calculate,input1,input2,input3,input4;
  11. //take user inputs here,
  12. calculate=distance(input1,input2,input3,input4);
  13. cout<<calculate<<endl;
  14. return 0;
  15. }
  16.  
  17. float distance(float input1,float input2,float input3,float input4)
  18. {
  19. float result,diff1,diff2,addition;
  20. diff1=input3-input1;
  21. diff2=input4-input2;
  22. diff1=diff1*diff1
  23. diff2=diff2*diff2;
  24. addition=diff1+diff2;
  25. result=sqrt(addition);
  26. return result;
  27. }
  28.  
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
Nov 7 '06 #3

Post your reply

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