top of page

C Factorial Table Or Number Programs -सी फैक्टोरियल टेबल या नंबर प्रोग्राम्स


C Programming Tutorial In Hindi - C Factorial Table Or Number Programs -सी फैक्टोरियल टेबल या नंबर प्रोग्राम्स  | Creative Bloke

यह सी प्रोग्राम फ़ंक्शन का उपयोग करके किसी दिए गए नंबर का फैक्टोरियल ढूंढता है। उदाहरण के लिए, फ़ंक्शन का उपयोग करके किसी दिए गए नंबर (5) का फैक्टोरियल फैक्टोरियल (5) = 120 होगा।


यदि आपको अभी तक प्रोग्राम के ड्राई रन या किसी अन्य प्रश्न की आवश्यकता है, तो कृपया कमेंट बॉक्स में एक टिप्पणी छोड़ दें या मुझे मेल करें, मुझे आपकी मदद करने में खुशी होगी।


इस ट्यूटोरियल में, हम फ़ंक्शन का उपयोग करके फैक्टोरियल खोजने के लिए C प्रोग्राम की अवधारणा पर चर्चा करेंगे


फ़ैक्टोरियल सभी सकारात्मक अवरोही पूर्णांक ( Descending integer ) का एक उत्पाद है जो एक निर्दिष्ट संख्या (n) से शुरू होता है और एक तक की गणना करता है।

For Example:


Factorial Of 5 Is :

5!=5*4*3*2*1=120

Factorial Of 4 Is :

4!=4*3*2*1=24

एक धनात्मक संख्या n का फ़ैक्टोरियल नीचे दिया गया है:


Factorial Of n Is :

n!=n*(n-1)*....2*1

सी प्रोग्रामिंग भाषा का उपयोग करके एक फैक्टोरियल की गणना करने के कई तरीके हैं। उनमें से कुछ का वर्णन इस प्रकार है।


उपयोगकर्ता अपनी इच्छानुसार नंबर प्रदान कर सकता है और अपने इनपुट के अनुसार फ़ैक्टोरियल प्राप्त कर सकता है।


Q:01. Write a program to find a the factorial of any given number?

OR

Write a program to find factorial of a number using function blocks?


<> Code Program :
#include <stdio.h>

int fact(int);

void main()
{
     int no, factorial;
     printf("Enter a number to calculate it's factorial \n");
     scanf("%d", &no);
     factorial = fact(no);
     printf("Factorial of the num(%d) = %d\n", no, factorial);
/*
printf("Factorial of the num(%d) = %d\n", no, fact(no));
another way of calling a function
comment above two lines if you want to use this
*/

}

int fact(int n)
{
    int i, f=1;
    for(i=1; i<=n; i++)
    {
        f = f*i;
    }
    
    return f;
}
This Program Output Is :
Enter a number to calculate it's factorial
5
factorial of the num(5) = 120


Q:02. Write a C program to find factorial of a number using method?

<> Code Program :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int factorial(int);
    int num;
    printf("Enter the number to find factorial\n");
    factorial(num); //call the function
    getch();
    return 0;
    }
    
    int factorial(num)
    { 
        //create function to find factorial
        int i, fact=1; //declare variables
        scanf("%d", &num);//get input from user
        for(i=1; i<=num; i++)
            {
               fact=fact*i; //calculate factorial
            }
    }
        printf("Factorial of given number is: %d\n", fact);
}
This Program Output Is :
Enter a number for find factorial
6
Factorial of the 6 is : 720

Q:03. Write a C program to find factorial of a number using the function with return?

<> Code Program :
#include <stdio.h>
#include <stdlib.h>

int factorial(int);
int main()
{
    int num, fact=1;
    printf("Enter the number to find factorial\n");
    scanf("%d", &num);//get input from user
    printf("Factorial of %d is: %d\n", num, factorial(num));
    //call the factorial function to display
    
    getch();
    return 0;
}

    int factorial(int num)
    {  
    //create function to find factorial
    int i, fact=1;  //declare variables

    for(i=1; i<=num; i++)
    fact=fact*i; //calculate factorial
    return(fact); //return fact to main

}
This Program Output Is :
Enter a number for find factorial
7
Factorial of the 7 is : 5040


Q:04. Write a C program to find factorial of a number using Ternary operator


<> Code Program :
#include <stdio.h>
#include <stdlib.h>

int factorial(int n) //user defined method to calculate factorial
 {
    return(n==1 || n==0) ? 1: n*factorial(n-1);//calculate factorial using ternary operator
}

int main()
{
    int num;
    printf("Enter the number to find factorial\n");
    scanf("%d", &num);//get input from user
    printf("factorial of %d is %d \n", num, factorial(num));
    //display factorial of given number
    
    getch();
    return 0;
}
This Program Output Is :
Enter the number to find factorial
8
Factorial of 8 is 40320

Recursive Solution ( पुनरावर्ती समाधान )

निम्नलिखित पुनरावर्ती सूत्र ( Recursive Formula ) का उपयोग करके फैक्टोरियल की गणना की जा सकती है।

n! = n * (n-1)!
n! = 1 if n = 0 or n = 1
<> Code Program :

फैक्टोरियल का कार्यान्वयन निम्नलिखित है।

// C program to find factorial of given number

#include <stdio.h>

// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
	if (n == 0)
	return 1;
	return n * factorial(n - 1);
}

int main()
{
	int num = 5;
	printf("Factorial of %d is %d", num, factorial(num));
	return 0;
}
This Program Output Is :
Factorial of 5 is 120

Iterative Solution ( पुनरावृत्त समाधान )

फैक्टोरियल की गणना पुनरावृत्त ( Iterative ) रूप से भी की जा सकती है क्योंकि बड़ी संख्या के लिए रिकर्सन महंगा हो सकता है। यहां हमने for और while loop दोनों का उपयोग करते हुए पुनरावृत्त दृष्टिकोण दिखाया है।


Using For loop :


<> Code Program :
#include <stdio.h>

// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
	int res = 1, i;
	for (i = 2; i <= n; i++)
	res *= i;
	return res;
}

int main()
{
	int num = 6;
	printf("Factorial of %d is %d", num, factorial(num));
	return 0;
}
This Program Output Is :
Factorial of 6 is 720

Using While loop:


<> Code Program :
// C program for factorial of a number

#include <stdio.h>

// function to find factorial of given number
unsigned int factorial(unsigned int n)
{
	if(n == 0)
	return 1;
	int i = n, fact = 1;
	
	while (n / i != n) 
	{
	   fact = fact * i;
	   i--;
	}
	return fact;
}

int main()
{
	int num = 7;
	printf("Factorial of %d is %d", num, factorial(num));
	return 0;
}
This Program Output Is :
Factorial of 7 is 5040

Q:05. Write a program to find factorial all numbers in given ranges?

अब यह आखिरी प्रोग्राम है जो दी गई रेंज में सभी नंबरों का फैक्टोरियल ढूंढेगा। उदाहरण के लिए, यदि उपयोगकर्ता 1 और 10 को दो संख्या ( श्रेणी या रेंज ) के रूप में दर्ज करता है। फिर प्रोग्राम 1 से 10 तक के सभी नंबरों का फैक्टोरियल ढूंढेगा और प्रिंट करेगा।

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

int findFact(int);
int main()
{
    int num1, num2, i;
    long int fact;
    printf("Enter Range: ");
    scanf("%d %d", &num1, &num2);
    if(num1<num2)
    {
        for(i=num1; i<=num2; i++)
        {
            fact = findFact(i);
            printf("\n Factorial of %d = %ld", i, fact);
        }
    }
    else
    {
        for(i=num2; i<=num1; i++)
        {
            fact = findFact(i);
            printf("\n Factorial of %d = %ld", i, fact);
        }
    }
    getch();
    return 0;
}

int findFact(int n)
{
    int i=n;
    long int f=1;
    while(i>0)
    {
        f = f*i;
        i--;
    }
    return f;
}
This Program Output Is :
Enter Range: 1
10

Factorial of 1 = 1
Factorial of 2 = 2
Factorial of 3 = 6
Factorial of 4 = 24
Factorial of 5 = 120
Factorial of 6 = 720
Factorial of 7 = 5040
Factorial of 8 = 40320
Factorial of 9 = 362880
Factorial of 10 = 3628800

Comments


bottom of page