Functions:

A function is a set of statements that take inputs, do some specific computation and produces output.

The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can call the function.

The general form of a function is:

return_type function_name([ arg1_type arg1_name, ... ])

{

code

}

Types of Functions in C:

The following examples will explain to you the available function types in C programming.

1.No argument and No Return value

In this method, We won’t pass any arguments to the function while defining, declaring, or calling it. This type of functions in C will not return any value when we call the function from main() or any sub-function. When we are not expecting any return value, but we need some statements to print as output. Then, this type of function in C is very useful.

1.WAP to Addition of two number using Function.

#include<stdio.h> void Addition();// Function Declaration void main() { Addition();//Calling of Function } void Addition()//Body of Function { int Sum, a = 10, b = 20; Sum = a + b; printf("\n Sum of a = %d and b = %d is = %d", a, b, Sum); }

Output:








2.No argument and with Return value

In this method, We won’t pass any arguments while defining, declaring, or calling the function. This type of function will return some value when we call it from main() or any sub method.

The Data Type of the return value will depend upon the return type of function declaration. For instance, if the return type is int then return value will be int.

1.WAP to Multiplication of two number using Function.

#include<stdio.h> int Multiplication()//if we write function before main then no need to declare separately. { int Multi, a = 20, b = 40; Multi = a * b; return Multi; } int main() { int Multi; Multi = Multiplication(); printf("\n Multiplication of a and b is = %d \n", Multi ); }

Output:







3.With argument and No Return value

If you observe the above two methods, No matter how many times you executive, it will give the same output. We don’t have any control over the values of the variables a and b because they are fixed values.

In real-time, we mostly deal with dynamic data means we have to allow the user to enter his own values rather than fixed ones.

This method allows us to pass the arguments to the function while calling it. But, This type of function will not return any value when we call it from main () or any sub method.

1.WAP to Addition of two user's taken numbers using Function.

#include<stdio.h> void Addition(int a, int b) { int Sum; Sum = a + b; printf("\n Additiontion of %d and %d is = %d \n", a, b, Sum); } void main() { int a, b; printf("\n Please Enter two integer values \n"); scanf("%d %d",&a, &b); Addition(a, b); //Calling with dynamic values }

Output:







4.With argument and with Return value

This method allows us to pass the arguments to the function while calling it. This type of function will return some value when we call it from main () or any sub-function. Data Type of the return will depend upon the return type of function declaration. For instance, if the return type is int then return value will be int.

This type of user-defined function is called a fully dynamic, and it provides maximum control to the end-user.

1.WAP to Multiplication of two user's taken numbers using Function.

#include<stdio.h>
int Multiplication(int a, int b)
{
  int Multi;  
Multi = a * b;
return Multi;
}
int main()
{
  int a, b, Multi;
printf("\n Please Enter two integer values \n");
  scanf("%d %d",&a, &b);
//Calling the with dynamic values
  Multi = Multiplication(a, b);
printf("\n Multiplication of %d and %d is = %d \n", a, b, Multi);                  
}
Output: