Function Introduction:
Suppose we will solve a larger problem,then we will devide that larger problem into smaller smaller unit / block and that block is known as function .
What is function ?
- Function is a subpart of a program and it is used to perform some specific tasks .
- Function Is also called as block statement .
- Here block means one sub program or we can say individual part or unit .
What is the Duty Of Function?
Function will take input ,process those inputs and finally produce some output .
Function syntax:
return-type function_name(parameters_list)
{
//write processing and output logic
}
Example :1
//simple function programm
#include<stdio.h>
void fun()
{
printf(“HELLO I AM A FUNCTION\n”);
}
int main()
{
printf(“1\n”);
fun();
printf(“2\n”);
fun();
return 0;
}
OUTPUT:-
1
HELLO I AM A FUNCTION
2
HELLO I AM A FUNCTION
Example:2
//simple function programm
#include<stdio.h>
void fun()
{
printf(“HELLO I AM A FUNCTION\n”);
}
int main()
{
fun();
fun();
return 0;
}
OUTPUT:-
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
Example:3
//simple function programm
#include<stdio.h>
void fun()
{
printf(“HELLO I AM A FUNCTION\n”);
}
int main()
{
int i;
for(i=1;i<=10;i++){
fun();
}
return 0;
}
OUTPUT:-
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION
HELLO I AM A FUNCTION