Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
sol2.c File Reference

Problem 7 solution. More...

#include <stdio.h>
Include dependency graph for sol2.c:

Functions

int main ()
 Main function. More...
 

Detailed Description

Problem 7 solution.

See also
Faster version problem_7/sol.c

Function Documentation

◆ main()

int main ( void  )

Main function.

Returns
0 on exit
12{
13 int n;
14 scanf("%d", &n);
15 int number_of_prime = 0;
16 for (int i = 2;; i++)
17 {
18 int divisors = 0;
19 for (int j = 1; j <= i; j++)
20 {
21 if (i % j == 0)
22 {
23 divisors++;
24 }
25 }
26 if (divisors == 2)
27 {
28 number_of_prime++;
29 if (number_of_prime == n)
30 {
31 printf("%d", i);
32 break;
33 }
34 }
35 }
36
37 return 0;
38}
static unsigned int divisors[]
Hack to store divisors between 1 & 20.
Definition: sol2.c:21