Program 2: Print the product of a series of numbers

/* Program 2: Print the product of a series of numbers */

       /* 1*2*3*4* …. *n */

 

#include<stdio.h>

int main()

{

        int i,prod=1,n;

        do

        {

                gotoxy(10,10);

                printf(“Enter any number (<=20) : “);

                scanf(“%d”,&n);

                if (n<1 || n>20)

                {

                        gotoxy(10,25);

                        printf(“Out of data range …. please try again”);

                 }

        }while(n<1 || n>20);

        gotoxy(10,10);

        printf(“The product of the series is as follows….”);

        gotoxy(10,12);

        for (i=1;i<=n;i++)

        {

                prod=prod*i;

                printf(“%d*”,i);

        }

        printf(“\b=%d”,prod);

        return 0;

}