> For the complete documentation index, see [llms.txt](https://mun.gitbook.io/c/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mun.gitbook.io/c/solution/6-function-and-recursion/5.1-types-of-user-defined-function.md).

# 5.1 Types of User Defined Function

## ৫.১ প্রকারভেদ: ইউজার ডিফাইনড ফাংশন (৪)

1. \[1] Write a user-defined function that prints "Hello World" inside the function \[Function Prototype: void print\_hello(void)]
2. \[2] Pass an integer number to a user-defined function and print the given integer number inside the function \[Function Prototype: void print\_int(int)]
3. \[3] Write a user-defined function that takes input of an integer number inside the function and returns the number \[Function Prototype: int input\_int()]
4. \[4] Calculate the summation of two integer numbers using a user-defined function and return the result \[Function Prototype: int summation(int, int)]

## সমাধান

### \[1] Write a user-defined function that prints "Hello World" inside the function \[Function Prototype: void print\_hello(void)]

{% code lineNumbers="true" %}

```c
#include<stdio.h>

void print_hello(void); // Function Prototype

int main(){

    print_hello(); // Function Calling
    
    return 0;
}

// Function Definition
void print_hello(void){
    printf("Hello World\n");
}
```

{% endcode %}

### \[2] Pass an integer number to a user-defined function and print the given integer number inside the function \[Function Prototype: void print\_int(int)]

{% code lineNumbers="true" %}

```c
#include<stdio.h>

void print_int(int num); // Function Prototype
//void print_int(int);

int main(){
    int a = 10;
    
    print_int(42); // Function Calling by Passing Value (Constant Literal)
    print_int(a);// Function Calling by Passing Value (Variable)
    
    return 0;
}

// Function Definition
void print_int(int num){
    printf("%d\n", num);
}
```

{% endcode %}

### \[3] Write a user-defined function that takes input of an integer number inside the function and returns the number \[Function Prototype: int input\_int()]

```c
#include<stdio.h>

int input_int(void); // Function Prototype

int main(){
    int number;
    
    number = input_int(); // Funcion Return Value Assignment
    printf("You entered: %d\n", number);
    
    return 0;
}

// Function Definition
int input_int(void){
    int num;
    printf("Enter an integer: ");
    scanf("%d", &num);
    return num;
}
```

### \[4] Calculate the summation of two integer numbers using a user-defined function and return the result \[Function Prototype: int summation(int, int)]

```c
#include<stdio.h>

int summation(int a, int b);
//int summation(int, int);

int main() {
    int a = 5;
    int b = 7;
    
    printf("Summation of %d and %d: %d\n", a, b, summation(a, b));
    
    return 0;
}

int summation(int a, int b) {
    int sum;
    sum a + b;
    return sum;
}
```
