Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

πŸŒ™