- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a given number is Pronic in C++
Here we will see, how to check whether a number is Pronic number or not. A number that can be arranged to form a rectangle, are called the pronic numbers. First few pronic numbers are: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342. The pronin numbers are product of two consecutive integers. So a pronic number n = x * (x + 1).
Here we will check and generate some pronic numbers.
Example
#include <iostream> #include <cmath> using namespace std; bool isPronicNumber(int num) { for (int i = 0; i <= (int)(sqrt(num)); i++) if (num == i * (i + 1)) return true; return false; } int main() { for (int i = 0; i <= 200; i++) if (isPronicNumber(i)) cout << i << " "; }
Output
0 2 6 12 20 30 42 56 72 90 110 132 156 182
Advertisements