- 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 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++
- C++ program to find unique pairs such that each element is less than or equal to N
- Find three integers less than or equal to N such that their LCM is maximum 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++
- Euler’s Totient function for all numbers smaller than or equal to n in java
- Print all numbers less than N with at-most 2 unique digits in C++
- Find Largest Special Prime which is less than or equal to a given number in C++
- Print all Jumping Numbers smaller than or equal to a given value in C++
- Print triplets with sum less than or equal to k in C Program
- Find N distinct numbers whose bitwise Or is equal to K in C++

- 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

Advertisements