hI,
IHave a doubt in writing a generic function in C.
Say for Example,
I need to add 2 numbers. 2 interger Numbers or 2 float Numbers using the same function add().
How do i call the add function i.e how do i send parameters.
How do i receive the parameters in add fucntion definition.
#include<stdio. h>
int main()
{
int choice;
int i1,i2;
float f1,f2;
printf("What type of number do u want to add?\n");
printf("1.Inter ger Nmbers\n2.Float Numbers\n Enter Choice:");
scanf("%d"&choi ce);
switch(choice)
{
case1:printf("A dd Interger Numbers:");
scanf("%d"&i1);
scanf("%d"&i2);
/*call to a generic function add() */
/* HOW DO I SEND PARAMETERS IN THE FUNCTION CALL */
add( ???);
break;
case 2: printf("Add Float Numbers:");
scanf("%d"&f1);
scanf("%d"&f2);
/*call to a generic function add() */
/* HOW DO I SEND PARAMETERS IN THE FUNCTION CALL */
add( ???);
break;
}
}
/* HOW DO I RECEIVE THE PARAMETERS IN THE GENERIC FUNCTION ADD FOR BOTH FLOAT AND INT VALUES */
add(????)
{
...............
..............
}
Please Help. Its urgent.
Thanks in advance.
IHave a doubt in writing a generic function in C.
Say for Example,
I need to add 2 numbers. 2 interger Numbers or 2 float Numbers using the same function add().
How do i call the add function i.e how do i send parameters.
How do i receive the parameters in add fucntion definition.
#include<stdio. h>
int main()
{
int choice;
int i1,i2;
float f1,f2;
printf("What type of number do u want to add?\n");
printf("1.Inter ger Nmbers\n2.Float Numbers\n Enter Choice:");
scanf("%d"&choi ce);
switch(choice)
{
case1:printf("A dd Interger Numbers:");
scanf("%d"&i1);
scanf("%d"&i2);
/*call to a generic function add() */
/* HOW DO I SEND PARAMETERS IN THE FUNCTION CALL */
add( ???);
break;
case 2: printf("Add Float Numbers:");
scanf("%d"&f1);
scanf("%d"&f2);
/*call to a generic function add() */
/* HOW DO I SEND PARAMETERS IN THE FUNCTION CALL */
add( ???);
break;
}
}
/* HOW DO I RECEIVE THE PARAMETERS IN THE GENERIC FUNCTION ADD FOR BOTH FLOAT AND INT VALUES */
add(????)
{
...............
..............
}
Please Help. Its urgent.
Thanks in advance.
Comment