Question

Define a function distance that consumes a point (i.e. 2 integers say x1, y1) and displays...

Define a function distance that consumes a point (i.e. 2 integers say x1, y1) and displays the distance(floating-point) between the point (x1, y1) and origin (0,0).

Note: the distance be rounded off to 2 decimal places.

For example:

Test Result
distance(2,3);
The distance from the origin will be 3.61.

In C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 *  C Program to calculate distance from the origin
 */

#include <stdio.h>
#include <math.h>

void distnace(int x1, int y1)
{
  float dis = sqrt((x1*x1)+(y1*y1));
  printf("The distance from the origin will be %.2f\n", dis);
}

int main(void) {
  distnace(2, 3);
  return 0;
}

Files : main.c saved https://Heavenly MatureParallelcomputing.imtusharsharma.repl.run /* * main.c C Program to calculate dist

Add a comment
Know the answer?
Add Answer to:
Define a function distance that consumes a point (i.e. 2 integers say x1, y1) and displays...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

  • Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n...

    Define a function called get_n_largest(numbers, n) which takes a list of integers and a value n as parameters and returns a NEW list which contains the n largest values in the parameter list. The values in the returned list should be in increasing order. The returned list must always be of length n. If the number of values in the original list is less than n, the value None should be repeated at the end of the returned list to...

  • The natural log of 2, (In 2) can be found using the power series below: In...

    The natural log of 2, (In 2) can be found using the power series below: In 2 1- Create an M-file function to implement this formula so that it computes and displays the values of In 2 as each term in the series is added. In other words, compute and display in sequence the values for up to the order term, n, as chosen by the user of the function. For each of the preceding, compute and display the percent...

  • Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development p...

    Designing functions Reminder: When designing functions, follow the given steps to reinforce good software development practices and problem solving strategies: a) Start by writing the documentation for the function. Use docstrings shown in lecture and lab. b) Write test calls to the function in your main function for the different cases of input the function will encounter. This will help you understand the behavior of the function and later behave as tests for your function. c) Define the function d)...

  • A random walk is a particular kind of probabilistic (pseudo-random) simulation that models certai...

    A random walk is a particular kind of probabilistic (pseudo-random) simulation that models certain statistical systems, such as Brownian motion of particles or molecules. Coin flipping is an example of a one-dimensional random walk--one dimensional because you only can go forward (when you flip heads) or backward (when you flip tails) along a straight line. Suppose you take a random walk of nsteps. How many steps away from your starting point would you expect to end up on average, if...

  • 2. (From the distance test to vector stretches) Assume that A, B, C are points in...

    2. (From the distance test to vector stretches) Assume that A, B, C are points in the plane are on a line where B is in the middle, İ.e dist(AC)-dist(AB) + dist(BC). The goal of this exercise is to check that this is equivalent to the vector description! We will make some use of vectors and their intuition. În particular, if the coordinates of A, B, C are (zaJa), (Tb,Yb), (Te'%), we can translate them with a vector [u, v]...

  • For this program you will build a modular equation evaluator (you may want to start from...

    For this program you will build a modular equation evaluator (you may want to start from your solution to programming assignment 1). Once again, you will write a C program that evaluates the equations provided below. The program must prompt the user for inputs for the equations and evaluate them based on the inputs. All equations should be placed into a single .c file. This means you should NOT have 7 Visual Studio projects or 7 .c files. All variables...

  • i need #6 but i believe #6 function needs to call #5 function. I would like...

    i need #6 but i believe #6 function needs to call #5 function. I would like this in C language, and have no pointers, arrays or strings (on function calling and parameters). Thanks! I have attached the other functions that you might need to call for function 6 1. Write and test a function called is_multiple_of that takes a integer n1, integer n2 and determines whether the second argument (n2) is a multiple of the first argument (n1). The function...

  • Calculator Project

    AssignmentYou will be designing a calculator complete with user interface to take input from the user, process a response, and produce the output.Step 1: Present a menuFirst thing you should do is present a menu to the user when your program is first ran. Make sure that the operations match the numbers presented below, otherwise the graders won't be able to grade your program.1. Cartesian distance 2. Vector x matrix 3. Normalize 4. Quit Enter command:You will present the menu and wait for the user to input their...

  • C++ CODE /* This is program project 2 on page 695. * Before you begin the...

    C++ CODE /* This is program project 2 on page 695. * Before you begin the project, please read the project description * on page 695 first. * * Author: Your Name * Version: Dates */ #include <iostream> #include <cmath> #include <cassert> using namespace std; class Fraction { public: // constructor Fraction(int a, int b); // generate a fraction which is a/b Fraction(int a); // generate a fraction which is a/1 Fraction(); // generate a fraction which is 0/1. i.e...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT