Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

C Program to Find Factorial of a Number

C Program to Find Factorial of a Number

✅ C Program to Find Factorial of a Number

#include <stdio.h>
int main( )
{
    int num, fact = 1;
    printf("Enter the number:\n");
    scanf("%d", &num);

    for(int i = 1; i <= num; i++)
    {
        fact = fact * i;
    }

    printf("Factorial of %d is %d\n", num, fact);
}
  

๐Ÿ“˜ Explanation:

This program calculates the factorial of a number using a for loop. The factorial of a number is the product of all positive integers less than or equal to that number.

  • Take a number as input from the user.
  • Initialize a variable fact with value 1.
  • Use a for loop from 1 to the given number.
  • Multiply each number with fact in every iteration.
  • Print the final factorial value.

Example: 5! = 5 × 4 × 3 × 2 × 1 = 120

๐Ÿงพ Sample Output:

Enter the number:
5
Factorial of 5 is 120
  

๐Ÿ”‘ Keywords:

C program factorial, factorial using for loop in C, number programs in C, loop examples in C, C programming basics, beginner C programs

๐Ÿ“Œ Hashtags:

#CProgramming #FactorialProgram #LearnC #CodingForBeginners #ForLoop #NumberPrograms #1printf

๐Ÿ” Search Description:

Learn how to calculate factorial of a number in C using for loop. Simple and beginner-friendly C program with explanation and sample output.

Comments

Popular Posts

๐ŸŒ™