C program to find factorial of a number. It is a simple calculation of a factorial method. This is a basic C tutorial for beginners. Sample source code for this program is given below,
FACTORIAL IN C PROGRAM
This C program is used to find the factorial series for “n” numbers. For example if the factorial is 3, then the calculation will be like this (3! = 3x2x1=6). It will calculate every values by using the looping statement of for loop (for(cn=num;cn>1;cn–)).
FACTORIAL CODE IN C:
Q: Write a C program to calculate factorial of a number.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| /* Title: Simple factorial program in c Author: Vinoth Selvaraj */ //Header files # include <stdio.h> # include <conio.h> void main() { //Program variables int cn,num,f=1; clrscr(); //Function to clear previous output printf ( "Enter the value:" ); //Display function scanf ( "%d" ,&num); //Getting input function for (cn=num;cn>1;cn--) //Looping statement { f = f * cn; } printf ( "Factorial of %d is %d" ,num,f); getch(); } |
No comments:
Post a Comment