diff --git a/dynamic_programming/Uglynumbers.cpp b/dynamic_programming/Uglynumbers.cpp new file mode 100644 index 0000000..a162d78 --- /dev/null +++ b/dynamic_programming/Uglynumbers.cpp @@ -0,0 +1,48 @@ + +// C++ program to find n'th Ugly number +# include +using namespace std; + +/* Function to get the nth ugly number*/ +unsigned getNthUglyNo(unsigned n) +{ + unsigned ugly[n]; // To store ugly numbers + unsigned i2 = 0, i3 = 0, i5 = 0; + unsigned next_multiple_of_2 = 2; + unsigned next_multiple_of_3 = 3; + unsigned next_multiple_of_5 = 5; + unsigned next_ugly_no = 1; + + ugly[0] = 1; + for (int i=1; i