File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed 
Learning/7. Challenges/3. Functions Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ // Program to find all the prime numbers between two intervals using a function. 
2+ 
3+ #include  <stdio.h> 
4+ 
5+ int  isPrime  (int  number ) {// ----------- create a function that checks if a number is prime or not 
6+  
7+  int  flag  =  0 ;// ------------------- create flag variable with value 0 
8+ 
9+  for  (int  i  =  2 ; i  <  number ; i ++ ) {
10+  if  (number  % i  ==  0 ) {// --- run loop from 2 to number - 1 
11+  flag  =  1 ;// ------- check if number is divisible by number between 2 to number - 1 
12+  break ;
13+  }
14+  else  {
15+  flag  =  0 ;
16+  }
17+  }
18+  if  (flag  ==  0 ) {// ------- check if flag is 0 which is condition isolated for prime number 
19+  printf ("%d\n" , number );// --- print prime number and add new line 
20+  }
21+ }
22+ 
23+ int  main () {
24+  
25+  int  x , y ;
26+  scanf ("%d %d" , & x , & y );
27+  
28+  for  (int  i  =  x ; i  <= y ; ++ i ) {// run the loop from x to y 
29+  isPrime (i );// for each iteration of loop call isPrime() 
30+  }
31+  
32+  return  0 ;
33+ }
                                 You can’t perform that action at this time. 
               
                  
0 commit comments