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