Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C++ Program to Find Factorial Using Inline Function

C++ Inline Function – Factorial of a Number

C++ Program to Find Factorial Using Inline Function


#include <iostream>
using namespace std;

inline int factorial(int n)
{
    int fact = 1;
    for(int i = 1; i <= n; i++)
        fact *= i;
    return fact;
}

int main()
{
    int n;
    cout << "Enter a number: ";
    cin >> n;

    cout << "Factorial = " << factorial(n);
    return 0;
}
  

πŸ“˜ Explanation:

This C++ program calculates the factorial of a number using an inline function.

The inline function factorial() multiplies all integers from 1 to n using a loop and returns the final result.

Declaring the function as inline suggests the compiler to replace the function call with the function body, improving performance for small functions.

🧾 Sample Output:

Enter a number:
5
Factorial = 120
  

πŸ”‘ Keywords:

C++ inline function factorial, factorial program in C++, inline factorial, C++ loop programs, C++ basics

πŸ” Search Description:

Learn how to calculate factorial of a number in C++ using inline function. This example includes code, explanation, and output.

πŸ“Œ Hashtags:

#CPlusPlus #InlineFunction #FactorialProgram #CPPBasics #LoopInCPP #1printf

Comments

Popular Posts

πŸŒ™