Create a small program by computer language C, it print primers in range (1, 6000).
Let’s compile it by emcc and generate a template html file.
#include <stdio.h>
const int N = 6000;
int primer[N],count;
char visit[N] = { 0 };
void GetPrimers()
{
count = 0;
for (int i = 2; i <= N; i++)//quick query
{
if (!visit[i]) primer[++count] = i; // means primer.
for (int j = 1; j <= count && primer[j] * i <= N; j++)
{
visit[i*primer[j]] = 1;
if (i % primer[j] == 0)break;
}
}
}
int main()
{
GetPrimers();
printf( "start to work, count is %d\n", count );
int end = 100000;
for( int i = 0; i < count; ++i)
{
if( primer[i] <= end )
{
printf("%d\t", primer[i]);
}
else {
break;
}
}
printf("\n");
return 0;
}
Download emsdk: git clone https://github.com/emscripten-core/emsdk.git
.
Then set up the tool.
# Download and install the latest SDK tools.
./emsdk install latest
# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest
# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
To generate html file.
calculate_primes git:(main) $ emcc main.c -o template.html
If you can’t find emcc in your terminal, please add its path in environment variable PATH
.
PATH=$PATH:/home/stephen/Downloads/emsdk/upstream/emscripten
Finally, open the HTML file by browser and see the result.