C Program to Find Prime Numbers Between Intervals Using Functions. - wordsclank.in

Monday 29 January 2018

C Program to Find Prime Numbers Between Intervals Using Functions.


A Prime number an integer which is divisible only by 1 and itself.In other word a whole number who have two factor 1 and the number itself.
For example 2, 3, 5, 7, 11, 13, 17, 23, ...

prime number, prime number in c


Here we make a user defined function primecheck() that will check and print all the prime numbers between the given interval.

PROBLEM STATEMENT:

Write a  Program in C to find prime numbers between intervals using functions.





SOURCE CODE:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include

void primecheck(int x,int y);

void main()

{

      int n, m;

      printf("Enter the first number:");

      scanf("%d",&n);

      printf("Enter the secound number:");

      scanf("%d",&m);

      primecheck(n, m);

}


void primecheck(int x,int y)

{

      int i,count=0,j;

      for(i = x; i <= y; i++)

      {

            for(j=1; j <= i; j++)

            {

  

                  if(i%j==0)

                  {

                        count = count + 1;

                  }

            }

       if(count == 2)

       {

             printf("%d",i);

       }

       count=0;

      }

}


OUTPUT:
prime number, prime number in c

If the user's first number is greater than the second number then the numbers need to be swapped first.


More topics on C programming:




    No comments:

    Post a Comment