Write a function "int count_factor(int)" to print the factors and return number of factors of a given number. Then using that function write another function "void isprime(int)" to check if it is a prime number or not.Write a function "int count_factor(int)" to print the factors and return number of factors of a given number. Then using that function write another function "void isprime(int)" to check if it is a prime number or not.

#include<stdio.h>
int count_factor(int n)
{
    int i=1,con=0;
    printf("\nThe factors are=");
    while(i<=n)
    {
        if(n%i==0)
        {
            con++;
            printf(" %d ",i);
        }
        i++;
    }
    return con;
}

void isprime(int n)
{
    if(count_factor(n)==2)
        printf("\n%d is a prime number\n");
    else
        printf("\n%d is a prime number\n");
}
main()
{
    int num;
    printf("\nEnter a number=");
    scanf("%d",num);
    printf("\nNumber of factors=",count_factor(num));
    isprime(num);
}

No comments:

Post a Comment