Friday, 26 July 2013

Chapter 3 solutions Problem [B][b]

Question-Write a program to find the factorial value of any number
entered through the keyboard.
Solution-This is one of most famous problem of loops. this is the best problem to get better understanding of loops. here is the solution.

#include<stdio.h>
int main()
{
int i=1,factorial=1,num=5;
printf("Enter any number\n");
scanf("%d",&num);
while(i<=num) /* while loop is good , but for loop is best */
{
factorial=factorial*i;
i++;
}
printf("Factorial Value=%d\n",factorial);
return 0;
}

No comments:

Post a Comment