- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here we will see how to print all factorial numbers less than or equal to n, a number N is said to be factorial number if it is a factorial of a positive number. So some factorial numbers are 1, 2, 6, 24, 120.

To print factorial numbers, we do not need to find the factorial directly. Starting from i = 1, print factorial*i. Initially factorial is 1. Let us see the code for better understanding.

#include <iostream> using namespace std; void getFactorialNumbers(int n) { int fact = 1; int i = 2; while(fact <= n){ cout << fact << " "; fact = fact * i; i++; } } int main() { int n = 150; getFactorialNumbers(n); }

1 2 6 24 120

- Related Questions & Answers
- Print all prime numbers less than or equal to N in C++
- Print all Semi-Prime Numbers less than or equal to N in C++
- Find maximum product of digits among numbers less than or equal to N in C++
- Find Multiples of 2 or 3 or 5 less than or equal to N in C++
- Find unique pairs such that each element is less than or equal to N in C++
- Find three integers less than or equal to N such that their LCM is maximum - C++
- Find three integers less than or equal to N such that their LCM is maximum in C++
- C++ program to find unique pairs such that each element is less than or equal to N
- Find maximum sum array of length less than or equal to m in C++
- How to find numbers in an array that are greater than, less than, or equal to a value in java?
- Minimum swaps required to bring all elements less than or equal to k together in C++
- Count numbers (smaller than or equal to N) with given digit sum in C++
- Print all numbers less than N with at-most 2 unique digits in C++
- Recursive program to print all numbers less than N which consist of digits 1 or 3 only in C++
- Euler’s Totient function for all numbers smaller than or equal to n in java

Advertisements