Answers for "prime or composite in c using function"

C
0

prime or composite in c using function

#include<stdio.h>

int prime_composite(int num);

void main()
{
    int n,ret;
    printf ("Enter a number: ");
    scanf ("%d",&n);

    ret = prime_composite(n);

    if(ret == 2 )
       printf("\nThe number is Prime\n");
    else
        printf("\nThe number is Composite\n");
}

int prime_composite(int num)
{
    int i, c=0;

    for (i=1;i<=num;i++)
    {
        if(num%i==0)
        c=c+1;
    }

    return c;
}
Posted by: Guest on June-23-2021

Code answers related to "prime or composite in c using function"

Code answers related to "C"

Browse Popular Code Answers by Language