-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_example.cpp
More file actions
155 lines (120 loc) · 5.87 KB
/
Copy pathc_example.cpp
File metadata and controls
155 lines (120 loc) · 5.87 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream> //C
#include <stdio.h> //C
#include <curl/curl.h> //C++
#include <string> //C++
void get_random_prime() {
CURL* curl;
CURLcode res;
char api_key[4] = "YOUR_API_KEY";
char include_explanations[6] = "true";
char include_prime_types_list[6] = "true";
char language[8] = "english";
curl = curl_easy_init();
std::string url = std::string("http://api.prime-numbers.io/get-random-prime.php?key=") + std::string(api_key) + std::string("&include_explanations=") + std::string(include_explanations) + std::string("&include_prime_types_list=") + std::string(include_prime_types_list) + std::string("&language=") + std::string(language);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
/* example.com is redirected, so we tell libcurl to follow redirection */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
}
void is_this_number_prime() {
CURL* curl;
CURLcode res;
char api_key[4] = "YOUR_API_KEY";
char include_explanations[6] = "true";
char include_prime_types_list[6] = "true";
char number[15] = "60309232769";
char language[8] = "english";
curl = curl_easy_init();
std::string url = std::string("http://api.prime-numbers.io/is-this-number-prime.php?key=") + std::string(api_key) + std::string("&number=") + std::string(number) + std::string("&include_explanations=") + std::string(include_explanations) + std::string("&include_prime_types_list=") + std::string(include_prime_types_list) + std::string("&language=") + std::string(language);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
}
void get_all_primes_between_two_numbers() {
CURL* curl;
CURLcode res;
char api_key[4] = "YOUR_API_KEY";
char include_explanations[6] = "false";
char include_prime_types_list[6] = "false";
char start[15] = "69";
char end[15] = "200";
char forced_number[15] = "53";
char language[8] = "english";
curl = curl_easy_init();
std::string url = std::string("http://api.prime-numbers.io/get-all-primes-between-two-numbers.php?key=") + std::string(api_key) + std::string("&start=") + std::string(start) + std::string("&end=") + std::string(end) + std::string("&forced_number=") + std::string(forced_number) + std::string("&include_explanations=") + std::string(include_explanations) + std::string("&include_prime_types_list=") + std::string(include_prime_types_list) + std::string("&language=") + std::string(language);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
}
void prospect_primes_between_two_numbers() {
CURL* curl;
CURLcode res;
char api_key[4] = "YOUR_API_KEY";
char include_explanations[6] = "false";
char include_prime_types_list[6] = "false";
char start[15] = "350";
char end[15] = "1000";
char language[8] = "english";
curl = curl_easy_init();
std::string url = std::string("http://api.prime-numbers.io/prospect-primes-between-two-numbers.php?key=") + std::string(api_key) + std::string("&start=") + std::string(start) + std::string("&end=") + std::string(end) + std::string("&include_explanations=") + std::string(include_explanations) + std::string("&include_prime_types_list=") + std::string(include_prime_types_list) + std::string("&language=") + std::string(language);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
}
void get_isolated_random_prime() {
CURL* curl;
CURLcode res;
char api_key[4] = "YOUR_API_KEY";
char include_explanations[6] = "false";
char include_prime_types_list[6] = "false";
char minimum_combined_prime_gap[4] = "250";
char forced_number[15] = "60309232769";
char language[8] = "english";
curl = curl_easy_init();
std::string url = std::string("http://api.prime-numbers.io/get-isolated-random-prime.php?key=") + std::string(api_key) + std::string("&minimum_combined_prime_gap=") + std::string(minimum_combined_prime_gap) + std::string("&forced_number=") + std::string(forced_number) + std::string("&include_explanations=") + std::string(include_explanations) + std::string("&include_prime_types_list=") + std::string(include_prime_types_list) + std::string("&language=") + std::string(language);
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
}
int main(void)
{
get_random_prime();
//is_this_number_prime();
//get_all_primes_between_two_numbers();
//prospect_primes_between_two_numbers();
//get_isolated_random_prime();
return 0;
}