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 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
factwith value 1. - Use a for loop from 1 to the given number.
- Multiply each number with
factin 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.
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