0% found this document useful (0 votes)
5 views

06_function_in_C

The document explains the concept of functions in C, distinguishing between predefined and user-defined functions. It outlines the three major points of user-defined functions: declaration, definition, and calling, along with syntax and examples. Additionally, it provides various function types and sample code demonstrating function usage in a C program.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

06_function_in_C

The document explains the concept of functions in C, distinguishing between predefined and user-defined functions. It outlines the three major points of user-defined functions: declaration, definition, and calling, along with syntax and examples. Additionally, it provides various function types and sample code demonstrating function usage in a C program.

Uploaded by

landeparth93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-------------------------------------------------------------------------

Function in C
-------------------------------------------------------------------------

What is function?

- Function is user-Define data type.


- There are two type of function.

1. Predefine function 2. User-Define function

Ex: ex:
sqrt(); void sum(int)
printf(); .....
scanf();
pow();
exit();

sqrt(2)
pow(2,3)
include<math.h>
include<stdlib.h>

exit(0);

User-define function

Three major points

1. Declaration of function
2. Function definition
3. Function calling

Syntax:
Return_type function_name(parameter or prototype);
........

Example:

void evenOdd(int a,int b,float f1, double ....)

Method of function type.

void evenOdd(void); // no-return_type with no-argument


void evenOdd(int,int); // no-return_type with argument
int evenOdd(void); // return_type with no-argument
float evenOdd(float,float); // return_type with argument

Example: 1
Code:
void evenOdd(void); // function declaration
void addition(void);

int main()
{
evenOdd(); // function calling
addition();
getch();
return 0;
}
void evenOdd(void) // function definition
{
int num;
printf("enter any number :");
scanf("%d",&num);

if(num%2== 0)
{
printf("%d is even number ",num);
}
else
{
printf("%d is odd number",num);

}
}

void addition(void)
{
int a,b;
printf("Enter two number : ");
scanf("%d%d",&a,&b);
printf("sum of number is : %d\n",a+b);
}

Example:

float calc(int ,float); //function declaration

void main()
{
int num1;
float num2;
clrscr();
printf("Enter integer number:");
scanf("%d",&num1);
printf("Enter float value : ");
scanf("%f",&num2);

result = calc(num1,num2);// 3, 5.4


printf("calculation is : %f",result);

getch();

float calc(int x,float y) // 3, 5.4


{

x=x*x;
y=y*x;

return x+y;
}

You might also like