Bifalgorithm post · Computer science one · Void Functions

How do C functions return values to the calling function?

How do C functions return values to the calling function? (Computer science one · Void Functions) — "18.1. Defining & Using Functions\n\ndouble getDistance(dou…

Ideas in this flowchart

  • Defining and using functions
  • The getDistance function calculates the distance between two points.
  • It receives the coordinates x1, y1, x2, and y2 as parameters.
  • It calculates the differences between the corresponding coordinates.
  • It returns the square-root distance formula result.
  • The getMonthlyPayment function calculates a monthly payment.
  • It receives principle, apr, and terms as parameters.
  • It calculates the monthly rate by dividing the APR by 12.
  • It calculates the payment using the principal, rate, and number of terms.
  • The return keyword specifies the value returned to the calling function.
Feed/

How do C functions return values to the calling function?

No cover

Channel

Computer science one

1 page

"18.1. Defining & Using Functions\n\ndouble getDistance(double x1, double y1, double x2, double y2) {\n\ndouble xDiff = (x1-x2);\n\ndouble yDiff = (y1-y2);\n\nreturn sqrt( xDiff * xDiff + yDiff * yDiff);\n\n}\n\ndouble getMonthlyPayment(double principle, double apr, int terms) {\n\ndouble rate = (apr / 12.0);\n\ndouble payment = (principle * rate) / (1-pow(1+rate, -terms));\n\nreturn payment;\n\n}\n\nThe keyword return is used to specify the value that is returned to the calling function."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.