rev='made'/> name='keywords'/> name='author'/> ANURANAN: UVa Solution 136 : Ugly Number

Welcome Note

Hi,
I'm Anisuzzaman Babla . I am a full stack Android Application Developer. I am working with Android for more than two years. I have completed my graduation from IIT, Jahangirnagar University. I have developed a series of commercially successful apps on Android. Moreover, 10+ of my Apps are live at Google play store. .
Thank You

UVa Solution 136 : Ugly Number


#include<stdio.h>
#define s 1501
int main(){
   int p2,p3,p5;
   int ugly[s];
   int a,b,c;
   int i;

  ugly[1]=p2=p3=p5=1;
 
  for(i=2;i<=1500;i++)  {
             a=2*(ugly[p2]);
                b=3*(ugly[p3]);
                c=5*(ugly[p5]);
                if(a<b && a<c){
                  ugly[i]=a;
                  p2++;
                }
                else if(b<a && b<c){
                  ugly[i]=b;
                  p3++;
                }
                else if(c<a && c<b){
                  ugly[i]=c;
                  p5++;
                }

else if(a==b){
                                p3++;
                                i--;
                }
                else if(a==c){
                    p5++;
                                i--;
                }
                else if(b==c){
                  p5++;
                  i--;
                }
  }

  printf("The 1500'th ugly number is %d.\n",ugly[1500]);
  return 0;
}