prime or composite in c using function

Solutions on MaxInterview for prime or composite in c using function by the best coders in the world

showing results for - "prime or composite in c using function"
Eleana
25 Jun 2018
1#include<stdio.h>
2
3int prime_composite(int num);
4
5void main()
6{
7    int n,ret;
8    printf ("Enter a number: ");
9    scanf ("%d",&n);
10
11    ret = prime_composite(n);
12
13    if(ret == 2 )
14       printf("\nThe number is Prime\n");
15    else
16        printf("\nThe number is Composite\n");
17}
18
19int prime_composite(int num)
20{
21    int i, c=0;
22
23    for (i=1;i<=num;i++)
24    {
25        if(num%i==0)
26        c=c+1;
27    }
28
29    return c;
30}
31