Tuesday, July 22, 2008

C program to find Ugly numbers

Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence

1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...

shows the first 11 ugly numbers. By convention, 1 is included.

Here is the program to find nth Ugly number



main()
{
int i, j, n, count = 0;
printf("Enter which ugly number you want\n");
scanf("%d", &n);
int b[n];
for(i = 1; count < n; i++)
{
j = i;
while(j % 2 == 0)
{
j = j / 2;
}
while(j % 3 == 0)
{
j = j /3;
}
while(j % 5 == 0)
{
j = j / 5;
}
if(j == 1)
{
b[count] = i;
count++;
}
}
printf("nth ugly number is %d", b[n-1]);
getch();
}

Thursday, July 17, 2008

Get rid of connection timedout error (110) with yum in fedora 9

To get rid of this error first check yum.conf, where your internet connection details have been set. Suppose if u r using proxy then edit yum.conf and add below line.
http_proxy="http://Proxy IP:port number

But you should be a root user to edit the file yum.conf

Then save it. Now, you don't have the problem sated above.