Question

Write a complete C program that prompts the user for the coordinates of two 3- D...

Write a complete C program that prompts the user for the coordinates of two 3- D points ( x1 , y1 , z1 ) and ( x2 , y2 , z2 ) and displays the distance between them computed using the following formula:

distance= square root of (x1-x2)2+(y1-y2)2+(z1-z2)2

Homework Answers

Answer #1

#include <stdio.h>
#include <math.h>
int main()
{
int x1,x2,y1,y2,z1,z2;
double distance;
printf("Enter the first 3-D point: ");
scanf("%d %d %d", &x1, &y1, &z1);
printf("Enter the second 3-D point: ");
scanf("%d %d %d", &x2, &y2, &z2);
distance = sqrt((x2-x1) * (x2-x1) + (y2-y1) *(y2-y1) +(z2-z1) * (z2-z1));
printf("Distance is %ld\n", distance);

return 0;
}

Output:

sh-4.2$   g++ -o main *.cpp                                                                                                                                                                                                                                            

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the first 3-D point: 1 2 3                                                                                                                                                                                                                                       

Enter the second 3-D point: 4 5 6                                                                                                                                                                                                                                      

Distance is 3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a complete program that prompts the user to enter the number of students and each...
Write a complete program that prompts the user to enter the number of students and each student’s score, then finally displays the highest score.(in C++)
Write a program that prompts the user to enter a string and displays the number of...
Write a program that prompts the user to enter a string and displays the number of characters it contains, fourth character, and last character. Note: The string may contain blanks. For example: “C++ programming is fun”. You should write a complete program.
Write a program that prompts the user to enter an integer number between 1 and 999....
Write a program that prompts the user to enter an integer number between 1 and 999. The program displays the sum of all digits in the integer if the input is valid; otherwise, it displays a message indicating that the integer is not between 1 and 999 and hence, is invalid. Name the program file Q1.cpp Example: if the user enters 12, sum of digits is 3. If the user enters 122, sum of digits is 5.
Write an application that prompts a user for two integers and displays every integer between them....
Write an application that prompts a user for two integers and displays every integer between them. Display There are no integers between X and Y if there are no integers between the entered values. Make sure the program works regardless of which entered value is larger. ------------------------------------------------------------------------------------------------- import java.util.Scanner; public class Inbetween {     public static void main (String args[]) {         // Write your code here     } }
Collapse Write a program that prompts the user to input a positive integer. It should then...
Collapse Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.) Turn in: Your source code for with The name of your program as a comment at the top...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
1. Write a complete program in C++ that does the following: [2] asks a user to...
1. Write a complete program in C++ that does the following: [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero) [3] reads the two numbers from the keyboard; [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one. [3] displays the result of floating-point division. Make sure to follow programming style guidelines.
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b,...
Write a C program, called logic_abc.c, that prompts the user to enter three integers a, b, c, and then computes the results of the following logical operations, in sequence: !a || !b++ && c (a-1 || b/2) && (c*=2) (a-- || --b) && (c+=2) a || !(b && --c)
C++ Homework on Loop Structure A treasure is hidden someplace – the treasures coordinates are (x1,...
C++ Homework on Loop Structure A treasure is hidden someplace – the treasures coordinates are (x1, y1)! The coordinates (x1, y1) are determined randomly, using the code that is listed at the end of this exercise. The purpose of the game is for the Explorer to find the Treasure! The explorer is allowed to go North, South, West or East by one step each time. The Explorer is first positioned at location (15,15). If the explorer goes North by one...
Write a program that prompts the user for the number of values for which it will...
Write a program that prompts the user for the number of values for which it will calculate the base 2 log of each value. Use a for loop to iterate the set of values and print the log for each. Here is the formula to change the base of a log: loga b = log10 b / log10 a Sample output appears below. This program will calculate the Base 2 log of a set of numbers<LINERETURN> ===============================================================<LINERETURN> Enter the upper...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT