Hello friends..Ugly number is a number whose prime factors are only 1,2,3 or 5.
I had written a program for finding n`th ugly number in the series.Now the series is 1,2,3,4,5,6,8,9,10,12,15...these are first 11 ugly no`s.
Now In my program if we put m=11 then output will be 15.
It will work only up to m=239,Onwords it doesn`t work.
plz help me for finding 1500`th ugly number.

[B]/*PROGRAM TO FIND AND PRINT 1500`th UGLY NUMBER*/[/B]
//UGLY NUMBER IS A NUMBER WHOSE PRIME FACTORS ARE 2,3 OR 5
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>

void main()
{
 long int i;
 int j,k,l,p,n,m=240,c,f=0,x[20];
 int flag=1;
 clrscr();
 for(i=1;i<=500000;i++)
 {
 n=i;
 k=0;
 for(j=1;j<=i;j++)
 {
  if(n%j==0)
  {
   k++;
   x[k]=j;
   n=n/j;
   j=1;
   }
   if(x[k]!=1 && x[k]!=2 && x[k]!=3 && x[k]!=5)
   {
    flag=0;
    break;
    }
   }
   if(flag==1)
   {
  c=0;
  for(p=1;p<=k;p++)
  {
   if(x[p]==1 || x[p]==2 || x[p]==3 || x[p]==5)
    c++;
   }
   if(c==k)
   {
    f++;
    if(f==m)
    {
     clrscr();
     printf("\n\nThe 1500`th ugly number is <%ld>.",i);
     getch();
     exit(0);
     }
    }
   }
   flag=1;
  }
  printf("error");
  getch();
 }
void main()
{int n=1,i=0;
clrscr();
while(i<1500)
{    n++;
if(n%2==0||n%3==0||n%5==0)
i++;


}
printf("%d",n);



getch();
}
commented: Use code tags next time +0

muraliaa, that has got to be one of the worst written codes ever, the indentation is all messed up, you havent used code tags, and you have your void main. Also you havent added any files to include, so the functions printf, getch and clrscr are all undefined. I wouldent consider this any help at all.

Not to mention - 2 YEARS TOO LATE!

commented: heh, I didn't notice that x] +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.