

- 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
Find all divisors of a natural number - Set 1 in C++
In this tutorial, we are going to write a program that finds all the divisors of a natural number. It's a straightforward problem. Let's see the steps to solve it.
Initialize the number.
Write a loop that iterates from 1 to the given number.
Check whether the given number is divisible by the current number or not.
If the above condition satisfies, then print the current number.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; void findDivisors(int n) { for (int i = 1; i <= n; i++) { if (n % i == 0) { cout << i << " "; } } cout << endl; } int main() { findDivisors(65); return 0; }
Output
If you run the above code, then you will get the following result.
1 5 13 65
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Questions & Answers
- Find all divisors of a natural number - Set 2 in C++
- Find all divisors of a natural number in java
- Find sum of divisors of all the divisors of a natural number in C++
- Sum of all proper divisors of a natural number in java
- Find the number of divisors of all numbers in the range [1, n] in C++
- Count all perfect divisors of a number in C++
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors in C++
- Construct a TM for adding 1 to a binary natural number?
- Find number from its divisors in C++
- Divisors of factorials of a number in java
- Check if a number is divisible by all prime divisors of another number in C++
- Sum of all subsets of a set formed by first n natural numbers
- Find largest sum of digits in all divisors of n in C++
- Counting divisors of a number using JavaScript
- Find the largest good number in the divisors of given number N in C++
Advertisements