prime numbers in c

Solutions on MaxInterview for prime numbers in c by the best coders in the world

showing results for - "prime numbers in c"
Neila
18 Aug 2018
1#include<stdio.h>
2main() {
3    int n, i, count=0;
4    printf("Enter Number");
5    scanf("%d",&n);
6   
7    for ( i = 1; i<= n; i++) {
8        if (n % i == 1) {
9            count++;
10        }
11    }
12    if( count == 2) {
13        printf("Prime Number");
14    }
15    else {
16        printf("Not A  Prime Number");
17    }
18}
Tim
17 Jun 2019
1#include <stdio.h>
2int main()
3{
4   int i, num, p = 0;
5   printf("Please enter a number: \n");
6   scanf("%d", &num);
7   for(i=1; i<=num; i++)
8   {
9      if(num%i==0)
10      {
11         p++;
12      }
13   }
14   if(p==2)
15   {
16      printf("Entered number is %d "\
17             "and it is a prime number.",num);
18   }
19   else
20   {
21      printf("Entered number is %d "\
22             "and it is not a prime number.",num);
23   }
24}
25