PreDefined Functions
- If any function already designed by the C Develophers is known as predefined functions .These are classified into following types
- printf()
- Scanf()
- getch()
- clrscr()
- sizeof() ...ete
UserDefined Function
If any function designed by the programmer is known as user defined function
Syntax
These functions are classified into fallowing typesParametarized Function: If any function signature contains list of parameters is known as Parametarized Function.
Syntax
NoParametarized Function: If any function signature does not contains list of parameters is known as NoParametarized Function.
Syntax
No Returntype With NoParametarized Function
No Returntype With Parametarized Function
Returntype With NoParametarized Function
Returntype With Parametarized Function
Syntax
returntype functionname(list of paramers/no parameters); //function Declaration returntype functionname(list of paramers/no parameters) //function Body { .... .... .... .... }in the above syntax first you declare the function.Ofter you declare the function body
These functions are classified into fallowing types
- Parametarized Function
- NoParametarized Function
Syntax
returntype functionname(datatype variable1,datatype variable2,....); //function Declaration returntype functionname(datatype variable1,datatype variable2,....) //function Body { .... .... .... .... }
Syntax
returntype functionname(); //function Declaration returntype functionname() //function Body { .... .... .... .... }Based on the return type these functions are classified into following types
- No Returntype With NoParametarized Function
- No Returntype With Parametarized Function
- Returntype With NoParametarized Function
- Returntype With Parametarized Function
#include<stdio.h> #include<conio.h> void max(); void max() { int x,y; printf("Enter x,y values"); scanf("%d%d",&x,&y); if(x>y) { printf("x is max"); } else { prinf("y is max"); } }; void main() { clrscr(); max(); getch(); }
#include<stdio.h> #include<conio.h> void max(int x,int y); void max(int x,int y) { if(x>y) { printf("x is max"); } else { prinf("y is max"); } }; void main() { clrscr(); int x,y; printf("Enter x,y values"); scanf("%d%d",&x,&y); max(x,y); getch(); }
#include<stdio.h> #include<conio.h> int max(); int max() { int x,y; printf("Enter x,y values"); scanf("%d%d",&x,&y); if(x>y) { return x; } else { return y; } }; void main() { clrscr(); printf("%d",max()); getch(); }
#include<stdio.h> #include<conio.h> int max(int x,int y); int max(int x,int y) { if(x>y) { return x; } else { return y; } }; void main() { clrscr(); int x,y; printf("Enter x,y values"); scanf("%d%d",&x,&y); printf("%d",max(x,y)); getch(); }
C - Recursion
The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.
Syntax :
Syntax :
void recursion() { recursion(); /* function calls itself */ } int main() { recursion(); }
#include<stdio.h> #include<conio.h> int factorial(int i) { if(i <= 1) { return 1; } return i * factorial(i - 1); } void main() { int i = 5; printf("Factorial of %d is %d//n", i, factorial(i)); getch(); }
No comments:
Post a Comment