Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Program to Find Factorial Using Inline Function
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
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment