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:           ...

Star Design using Python program

Star Design import turtle turObj = turtle.Turtle() turObj.getscreen().bgcolor("#555555") turObj.speed(10) def star(turtle, size):     if size <=10:         return     else:         for i in range(30):             turObj.color("#FEACFF")             turObj.forward(i * 15)             turObj.right(144)            star(turObj,100)        turtle.done() Output:

Multiplication of Matrices

/*Multiplication of Matrices*/ #include<stdio.h> #include<conio.h> #include<math.h> void main() {    int a[10][10], b[10][10], c[10][10];    int i,j,n,m,k;    clrscr();    printf("\n\t Multiplication of two matrices");    printf("\nEnter the no. of row and columns:");    scanf("%d%d",&m,&n);    printf("\nEnter the first matrix:\n");    for(i=0;i<m;i++)    {      for(j=0;j<n;j++)      { scanf("%d",&a[i][j]);      }    }    printf("\nEnter the Second matrix:\n");    for(i=0;i<m;i++)    {      for(j=0;j<n;j++)      { scanf("%d",&b[i][j]);      }    }    printf("\nMultiplication of two matrices:\n");    for(i=0;i<m;i++)    {      for(j=0;...