Write functions to add, multiply, subtract two numbers and call the functions from the main program using a function pointer.
CODING:
#include <stdio.h>
#include<conio.h>
int add(int x,int y)
{
return x+y;
}
int mul(int x,int y)
{
return x*y;
}
int sub(int x,int y)
{
return x-y;
}
void main()
{
int (*a)(int,int);
int (*m)(int,int);
int (*s)(int,int);
int x,y,z;
clrscr();
a=add;
m=mul;
s=sub;
x=a(5,3);
y=m(5,3);
z=s(5,3);
printf("\nAdd\t\t: %d",x);
printf("\nProduct\t\t: %d",y);
printf("\nSubtract\t: %d",z);
getch();
}
CODING:
#include <stdio.h>
#include<conio.h>
int add(int x,int y)
{
return x+y;
}
int mul(int x,int y)
{
return x*y;
}
int sub(int x,int y)
{
return x-y;
}
void main()
{
int (*a)(int,int);
int (*m)(int,int);
int (*s)(int,int);
int x,y,z;
clrscr();
a=add;
m=mul;
s=sub;
x=a(5,3);
y=m(5,3);
z=s(5,3);
printf("\nAdd\t\t: %d",x);
printf("\nProduct\t\t: %d",y);
printf("\nSubtract\t: %d",z);
getch();
}
Comments
Post a Comment