Square-free Number in C

Square-free number


square-free number is a natural number that contains no powers greater than 1 in its prime factorization. In other words, if x is our number, and is the prime factorization of x into r distinct primes, then ai2 is always false for square-free x.

Note: we assume here that x itself must be greater than 1; hence 1 is not considered square-free. However, one must be alert to the particular context in which “square-free” is used as to whether this is considered the case.
The name derives from the fact that if any ai were to be greater than or equal to two, we could be sure that at least one square divides x (namely, pi2.)

A number is called a square free number if there does not exist a number greater than 1, whose square divides the number evenly/perfectly. For example, number 8 is not a square free number as number 4 (which is square of 2), divides 8. Similarly, number 4 is also not a square free number. However numbers 1, 3, 6 all are square free numbers.
Square Free Number


Code of Square- free Number: C program !


#include

int isSquareFree(int n)
{
    int i;

    for(i=2;i<=n; i++)
        if(n%i==0)
            if(n%(i*i)==0)
                return 0;
    return 1;
}

int main()
{
    int number;
loop:
    printf("Enter a number to check it's a Square-free Number or not: ");
    scanf("%d",&number);

    if(isSquareFree(number)==1)
        printf("Square-free Number!\n\n");
    else
        printf("Not Square-free Number!\n\n");

    goto loop;

    return 0;
}

Output:

Enter a number to check it's a Square-free Number or not:6
Square-free Number!
Enter a number to check it's a Square-free Number or not:9
Not Square-free Number!



Thanks of reading this blog!💓
Like ,Comment & Share ;



*

إرسال تعليق (0)
أحدث أقدم