0

Functions

A program that calculates the area of a circle using functions. So area of a circle is Pi*r² right? So I have the question in function calling when I call the function can I write it down like (please assume the variables are already given) : Answer = area_circle (radius, radius, pi); And in case you want to know the prototype I have written it's: int area_circle ( int, float); P. S - Second day I touched functions and I am finding it confusing so please let me know where I have gone wrong.

18th Nov 2019, 6:11 AM
Dipanjan Basu
Dipanjan Basu - avatar
3 ответов
+ 1
I would recommend you to give the prototype as- int area_circle(double,double); OR int area_circle(float,float); Also while passing the variables you need not give radius twice. You can write - answer = area_circle(radius,pi);
18th Nov 2019, 6:16 AM
Avinesh
Avinesh - avatar
+ 1
Sure! Thank you! So you mean to say while we are doing the function call we just use the elements required to do the calculation right? Also I haven't declared pi in the main function I have declared it in the function body is that okay?
18th Nov 2019, 6:21 AM
Dipanjan Basu
Dipanjan Basu - avatar
+ 1
Yes but if you are not declaring the pi inside main then you should only pass radius in the function call.
18th Nov 2019, 7:43 AM
Avinesh
Avinesh - avatar