Headlines
Loading...
C program to Write a function int product(int n, …) to take variable argument list.

C program to Write a function int product(int n, …) to take variable argument list.

 Write a function int product(int n, …) to take variable argument list.*/

 

#include<stdio.h>

#include<conio.h>

#include<stdarg.h>

 

void main()

{

            int x=3, y=9, z=3;

            int prod(int a,...);

 

            clrscr();

            printf("\nArguments passed are:  %d  %d  %d",x,y,z);

            printf("\n\nProduct:  %d",prod(3,3,9,3));

 

            getch();

}

 

int prod(int num,...)

{

            int i, p=1;

 

            va_list prodarr;

 

            va_start(prodarr,num);

 

            for(i=0;i<num;i++)

            {

                        p = p * (va_arg(prodarr,int));

            }

 

            va_end(va_list);

            return(p);

}

 

/*Output

 

Arguments passed are:  3  9  3

 

Product:  81

*/

 

 

 

 

*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***