Code Competitions

Coding competition

Monday, 13 May 2013

Program to pass function to through another function(pointer to function)

#include<stdio.h>
#include<conio.h>
int add(float,float);
int sub(float,float);
void fun_cal_fun(float,float,int(*)(float,float));
void main()
{
    float a,b,c;
       //    int *ptr;
    clrscr();
    printf("Enter two numbers");
    scanf("%f%f",&a,&b);
    fun_cal_fun(a,b,add);
    fun_cal_fun(a,b,sub);
    c=sizeof(int(*)(float,float));
     //    c=sizeof(*ptr);
    printf("\nsize of pointer variable = %f",c);
    getch();
}
void fun_cal_fun(float a,float b,int(*fun)(float,float))
{
    fun(a,b);
}
int add(float a,float b)
{
    printf("sum of numbers = %f",a+b);
    return;
}
int sub(float a,float b)
{
    printf("\nsubtraction of two numbers = %f",a-b);
    return;
}

No comments:

Post a Comment