-->

WAP to get factorial value of a number.

//WAP to get factorial value of a number.
#include<stdio.h>
include<conio.h>
void main()
{
   int number,fact=1,i;
   printf("enter any positive number\n");
  scanf("%d",&number); 
 for(i=1;i<=number;i++)
    {
     fact=fact*i;
   }
 printf("the factorial value for entered number=%d is =%d\n",number,fact);
getch();
}
-----------------------------------------------------------------------------------
Or
-------------------------------------------------------------------------------
//program to get factorial value of a positive number
#include<stdio.h>
include<conio.h>
void main()
{
   int number,fact=1,i;
   printf("enter any positive number\n");
  scanf("%d",&number);
if(number>0)

 for(i=1;i<=number;i++)
    {
     fact=fact*i;
   }
}
else
{
printf("the number is not +ve\n");
}
 printf("the factorial value for entered number=%d is =%d\n",number,fact);
getch();
}

No comments:

Post a Comment