Function receive argument

Syntax:
return-type function-name(data-type arg1, data-type arge2, data-type arg3,…..data-type argN)
Here arg stands for arguments.arg1, arge2 are as like as variable name
Example: 
function name is: example
return-type is: void
2 arguments: first argument is int type and second argument is float type.
So this function can be written as
void example(int a, float b)
{

}
Problem: Write a C program to do the following

  • Determine the area of a circle while user will input the value of radius from keyboard
  • Use a user defined function named circle. This function will receive two values while it will be called. One is the radius and another is the value of PI(3.1416)
  • circle function will return area of circle

Solution:
Let radius is always an integer number. So fist argument is int type. value of PI is fractional. So second argument is float.Area is the product of fraction and integer number. So return type should be float.Complete solution is:

NOTE

area=circle(radius,3.1416);
Here radius is int type data and it will be assigned to the first argument ‘int r’. 3.1416 is fraction type data and it will be assigned to ‘float PI’. So if you call circle function as follows:
area= circle(3.1416,radius); it will show error. So sequence of argument is a fact to be considered.


Next Previous