Write a program to calculate
the addition, subtraction, multiplication and division of two numbers by using
the concept of user define function.
Those functions whose
operations are defined by the user are called user defined function. Following
functions are included in user define function;
-
Function
prototype
Function prototype know which type of function
is return by the function, name of the function, how many argument or parameter
is being used by a function and type of argument or parameter used by a
function.
Syntax:
-
Return
type function name (datatype,
datatype)
-
Function call statement
This function call is an independent module
which contain main statement which contain main statement which is written for
the purpose of execution of the task.
Syntax:
-
Var.
name = function name (arg1, arg2)
-
Function
definition
It is
that part of the program where the required execution statement is written. It is
the main part of the program which is used to implement the concept of
modularity in a program.
Syntax: -
Return
type function name (datatype1 arg1,
datatype2 arg2)
Program: -
#include<stdio.h>
#include<conio.h>
int sum(int, int);
int subtraction(int, int
);
int multiplication(int,
int );
int divisiomn(int, int);
void main()
{
int a,b,c;
clrscr();
printf("\n enter the
first number=");
scanf("%d",&a);
printf("\n enter the
second number=");
scanf("%d",&b);
c=sum(a,b);
printf("\n sum is
=%d", c);
c=subtraction(a,b);
printf("\n
subtraction is=%d",c);
c=multiplication(a,b);
printf("\n
multiplication is =%d",c);
c=division(a,b);
printf("\n division
is =%d",c);
getch();
}
int sum(int a, int b )
{
int c;
c=a+b;
return c;
return c;
}
int subtraction(int a,
int b)
{
int c;
c=a-b;
return c;
return c;
}
int multiplication(int a,
int b)
{
int c;
c=a*b;
return c;
return c;
}
int division(int a, int
b)
{
int c;
c=a/b;
return c;
return c;
}
Output: -
Enter
the first number =
Enter
the second number =
Sum=
Subtraction
=
Multiplication
=
Division
=
Comments
Post a Comment