UGLY NUMBER OR NOT

Consider the following I/O samples.




SAMPLE INPUT: 12

SAMPLE OUTPUT:  UGLY NUMBER


    UGLY NUMBERS are those whose prime factors are 2, 3 and 5.






C PROGRAM:

#include <stdio.h>

int main()

{

    int num,fact=1;

    scanf("%d",&num);

    while(num!=1)

    {

        fact++;

        while(num%fact==0)

            num=num/fact;

    }

    if(fact<=5)

        printf("UGLY NUMBER");

    else

        printf("NOT AN UGLY NUMBER");
        
    return 0;

    
}





OUTPUT:



                 





The given source code in C program "FOR UGLY NUMBER OR NOT" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free. 
If you have any feedback about this article and want to improve this, please comment in the comment section.

Comments

Popular posts from this blog

C PROGRAM TO PRINT ALL LEAP YEARS IN A GIVEN RANGE

INVERTED PYRAMID STAR PATTERN

Design a way to sort the list of positive integers in the descending order according to frequency of elements. The elements with integers with higher frequency come before with lower frequency elements with same frequency come in the same order as they appear the values.