Skip to main content

Factorial Program in C using Recursion

#include<stdio.h>
#include<conio.h>

void main()
{
   int n, fact;

   clrscr();
   printf("\nEnter a Number: ");
   scanf("%d",&n);

   fact = factorial(n);

   printf("\nThe Factorial value is: ");
   printf("%d",fact);
   getch();
}

factorial(int n)
{
    int fact;

    if(n==1)
    {
       return(1);
    }
    else
    {
fact = n * factorial(n-1);
return fact;
    }
}

Output:

Enter the value: 5

The Factorial value is: 120

Comments

Popular posts from this blog

Creating a Realtime Clock using Python program

Clock from turtle import * from datetime import datetime def jump(distanz, winkel=0):     penup()     right(winkel)     forward(distanz)     left(winkel)     pendown() def hand(laenge, spitze):     fd(laenge*1.15)     rt(90)     fd(spitze/2.0)     lt(120)     fd(spitze)     lt(120)     fd(spitze)     lt(120)     fd(spitze/2.0) def make_hand_shape(name, laenge, spitze):     reset()     jump(-laenge*0.15)     begin_poly()     hand(laenge, spitze)     end_poly()     hand_form = get_poly()     register_shape(name, hand_form) def clockface(radius):     reset()     pensize(7)     for i in range(60):         jump(radius)         if i % 5 == 0:           ...

Inserting,Deleting and Updating table values in Database using Python Programming

Insert,Delete and Update import tkinter as tk from tkinter import * import mysql.connector import datetime def IsValidDate(InputDate):     day = InputDate[:2]     month = InputDate[3:5]     year = InputDate[6:]         IsValid = True         try :         datetime.datetime(int(year),int(month),int(day))     except ValueError :         IsValid = False     return IsValid def FormatDBDate(InputDate):     dt = InputDate[6:] + "-" + InputDate[3:5] + "-" + InputDate[:2]     return dt    def FormatEDDate(InputDate):     dt =  InputDate[8:] + "/" + InputDate[5:7] + "/" + InputDate[:4]     return dt  def DeleteEmployee(id, eid, ename, dob, doj, adr, cty, pcd, mob, eml, gen, dep):     conn=mysql.connector.connect(user='root',password='harsha',host='localhost', datab...

Palindrome of a given number using C

#include<stdio.h> #include<conio.h> void main() {    long n, r, ri=0, oi;    clrscr();    printf("\nEnter a number: ");    scanf("%ld",&n);    oi = n;    while(oi!=0)    {       ri = ri * 10;       ri = ri + oi % 10;       oi = oi / 10;    }    if(n==ri)    {       printf("\nThe given number is a Palindrome");    }    else    {       printf("\nThe given number is not a palindrome");    }    getch(); } Output: Enter a number: 1221 The given number is a Palindrome Output: Enter a number: 953212359 The given number is a Palindrome