Newsgroup: it.lavoro.informatica
Titolo: come faccio ad eseguire questo codice?

Dovrebbe essere C , esiste un ambiente online di esecuzione?
 
Ad esempio: 
 
 
 
Il lato del decagono regolare inscritto in una circonferenza di raggio unitario e' uguale al rapporto aureo (sqrt(5)-1)/2 = phi
 
https://ibb.co/jDBd5k1
 
 
---
 
L'apotema del pentagono regolare inscritto in una circonferenza di raggio unitario e' uguale al semireciproco del rapporto aureo (sqrt(5)+1)/4 = 1/2phi
 
https://ibb.co/gg0jZF8
 
 
 
--- source deca.txt---
ox=SCREENWIDTH/4;oy=SCREENHEIGHT/3;
r=SCREENHEIGHT/5;
double ptx[10],pty[10];
int in;
ptx[0]=ox+r;pty[0]=oy;
for(in=1;in<10;++in) {
ptx[in]=ox+cos(in*M_PI/5)*r;
pty[in]=oy-sin(in*M_PI/5)*r;
line(ptx[in],pty[in],ptx[in-1],pty[in-1],YELLOW);
}
ax=ptx[0];ay=pty[0];
px=ptx[1];py=pty[1];
bx=ox;by=oy-r/2;
gx=(ax+(sqrt(5)-1)*bx)/sqrt(5);gy=(ay+(sqrt(5)-1)*by)/sqrt(5);
circle(ox,oy,ox+r,oy,GREEN);
line(ox,oy,ax,ay,MAGENTA);
line(ax,ay,bx,by,MAGENTA);
line(bx,by,ox,oy,MAGENTA);
line(ox,oy,ox-r,oy,CYAN);
circle(bx,by,gx,gy,BLUE);
circle(ax,ay,gx,gy,BLUE);
text(ox,oy,"O");
text(ax,ay,"A");
text(px,py,"P");
text(bx,by,"B");
text(gx,gy,"G");
printf("\e[%d;%dHREGULAR DECAGON", 1, 1);
printf("\e[%d;%dH---------------", 2, 1);
printf("\e[%d;%dHOA = 2 [Hyp.]",TERMINALHEIGHT*2/3,1);
printf("\e[%d;%dHBO = BG = OA/2 = 1",TERMINALHEIGHT*2/3+1,1);
printf("\e[%d;%dHAB = sqrt(5)",TERMINALHEIGHT*2/3+2,1);
printf("\e[%d;%dHAG = AP = sqrt(5)-1",TERMINALHEIGHT*2/3+3,1);
printf("\e[%d;%dHAP/OA = (sqrt(5)-1)/2 = phi [Th.]",TERMINALHEIGHT*2/3+4,1);
 
 
$ ./minigeo "`cat deca.txt`"
 
 
 
--- source penta.txt ---
ox=SCREENWIDTH/4;oy=SCREENHEIGHT/3;
r=SCREENHEIGHT/5;
ax=ox+r;ay=oy;
bx=ox+r;by=oy-r/2;
cx=(bx*(sqrt(5)+1)-ox)/sqrt(5);cy=(by*(sqrt(5)+1)-oy)/sqrt(5);
gx=(ox+cx)/2;gy=(oy+cy)/2;
a=atan(0.5)-M_PI/5;
px=ox+cos(a)*r;py=oy-sin(a)*r;
qx=ox+cos(a+2*M_PI/5)*r;qy=oy-sin(a+2*M_PI/5)*r;
rx=ox+cos(a+4*M_PI/5)*r;ry=oy-sin(a+4*M_PI/5)*r;
sx=ox+cos(a+6*M_PI/5)*r;sy=oy-sin(a+6*M_PI/5)*r;
tx=ox+cos(a+8*M_PI/5)*r;ty=oy-sin(a+8*M_PI/5)*r;
circle(ox,oy,ox+r,oy,GREEN);
circle(bx,by,ax,ay,BLUE);
circle(ox,oy,gx,gy,BLUE);
line(px,py,qx,qy,YELLOW);
line(qx,qy,rx,ry,YELLOW);
line(rx,ry,sx,sy,YELLOW);
line(sx,sy,tx,ty,YELLOW);
line(tx,ty,px,py,YELLOW);
line(ox,oy,ax,ay,MAGENTA);
line(ax,ay,bx,by,MAGENTA);
line(bx,by,gx,gy,MAGENTA);
line(ox,oy,gx,gy,CYAN);
line(bx,by,cx,cy,MAGENTA);
text(ox,oy,"O");
text(ax,ay,"A");
text(bx,by,"B");
text(cx,cy,"C");
text(px,py,"P");
text(qx,qy,"Q");
text(gx,gy,"G");
printf("\e[%d;%dHREGULAR PENTAGON", 1, 1);
printf("\e[%d;%dH----------------", 2, 1);
printf("\e[%d;%dHOA = 2 [Hyp.]",TERMINALHEIGHT*2/3,1);
printf("\e[%d;%dHAB = BC = OA/2 = 1",TERMINALHEIGHT*2/3+1,1);
printf("\e[%d;%dHOB = sqrt(5)",TERMINALHEIGHT*2/3+2,1);
printf("\e[%d;%dHOC = sqrt(5)+1",TERMINALHEIGHT*2/3+3,1);
printf("\e[%d;%dHOG = OC/2 = (sqrt(5)+1)/2",TERMINALHEIGHT*2/3+4,1);
printf("\e[%d;%dHOG/OA = (sqrt(5)+1)/4 = 1/2phi [Th.]",TERMINALHEIGHT*2/3+5,1);
 
 
$ ./minigeo "`cat penta.txt`"
 
 
 
 
========== minigeo ==========
#!/bin/bash
# minigeo [License: Public Domain]
 
trap "rm -f ${0}.tmp ${0}.tmp.c" 0
 
if ! type gcc &> /dev/null; then
echo "Error. GNU C compiler not found"
exit 1
fi
 
f=/sys/class/graphics/fb0/virtual_size
if test ! -e "$f"; then
echo "Error. Frame buffer not found"
exit 1
fi
SCREENWIDTH=`cat "$f" | cut -d "," -f 1`
SCREENHEIGHT=`cat "$f" | cut -d "," -f 2`
TERMINALWIDTH=`stty size | cut -d " " -f 2`
TERMINALHEIGHT=`stty size | cut -d " " -f 1`
 
if test $# != 1; then
echo "Usage: $0 \"...raw C code...\""
echo 'Example: '"$0"' "circle(300,300,100,300,BLUE); line(100,300,500,300,GREEN); text(300,300,\"OK\");"'
exit 1
fi
INPUTDATA=$1
 
########################################
 
{
cat << EOF
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>
 
#define SCREENWIDTH $SCREENWIDTH
#define SCREENHEIGHT $SCREENHEIGHT
#define TERMINALWIDTH $TERMINALWIDTH
#define TERMINALHEIGHT $TERMINALHEIGHT
 
int screen[SCREENHEIGHT][SCREENWIDTH];
 
#define BLACK 0x00000000
#define WHITE 0x00FFFFFF
#define LTGRAY 0x00AAAAAA
#define GRAY 0x00555555
#define RED 0x00FF0000
#define GREEN 0x0000FF00
#define BLUE 0x000000FF
#define CYAN 0x0000FFFF
#define MAGENTA 0x00FF00FF
#define YELLOW 0x00FFFF00
 
////////////////////////////////////////
 
void pset(double x, double y, int colour) {
int ix, iy;
ix = (int)round(x);
iy = (int)round(y);
if(ix < 0 || ix >= SCREENWIDTH || iy < 0 || iy >= SCREENHEIGHT) return;
screen[iy][ix] = colour;
}
 
////////////////////////////////////////
 
void swap(double *a, double *b) {
double tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
 
void vline(double x, double y1, double y2, int colour) {
if(y1 > y2) swap(&y1, &y2);
while(y1 <= y2) {
pset(x, y1, colour);
++y1;
}
}
 
void line(double x1, double y1, double x2, double y2, int colour) {
double dx, dy, m;
double x, y, exy;
 
if(x1 == x2) { vline(x1, y1, y2, colour); return; }
if(x1 > x2) { swap(&x1, &x2); swap(&y1, &y2); }
 
dx = x2 - x1;
dy = y2 - y1;
m = dy / dx;
 
x = 0; exy = 0;
while(1) {
y = m * x;
vline(x1+x, y1+exy, y1+y, colour);
exy = y;
 
if(x == dx) break;
++x;
if(x > dx) x = dx;
}
}
 
////////////////////////////////////////
 
void circle(double cx, double cy, double px, double py, int colour) {
double r, x, y, exy;
 
r = sqrt(pow(cx-px, 2) + pow(cy-py, 2));
 
x = 0; exy = r;
while(1) {
y = sqrt(r*r - x*x);
vline(cx+x, cy+exy, cy+y, colour);
vline(cx+x, cy-exy, cy-y, colour);
vline(cx-x, cy+exy, cy+y, colour);
vline(cx-x, cy-exy, cy-y, colour);
exy = y;
 
if(x == r) break;
++x;
if(x > r) x = r;
}
}
 
////////////////////////////////////////
 
void text(double x, double y, char *t) {
int ix, iy;
ix = (int)round(x * TERMINALWIDTH / SCREENWIDTH + 1);
iy = (int)round(y * TERMINALHEIGHT / SCREENHEIGHT);
if(ix < 1 || ix > TERMINALWIDTH || iy < 1 || iy > TERMINALHEIGHT) return;
printf("\e[%d;%dH%s", iy, ix, t);
}
 
////////////////////////////////////////
 
void fb(void) {
int fd;
fd = open("/dev/fb0", 1);
write(fd, screen, SCREENWIDTH * SCREENHEIGHT * sizeof(int));
close(fd);
}
 
////////////////////////////////////////
 
int main(void) {
double a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
double ax,ay,bx,by,cx,cy,dx,dy,ex,ey,fx,fy,gx,gy,hx,hy,ix,iy,jx,jy,kx,ky,lx,ly,mx,my,nx,ny,ox,oy,px,py,qx,qy,rx,ry,sx,sy,tx,ty,ux,uy,vx,vy,wx,wy,xx,xy,yx,yy,zx,zy;
 
$INPUTDATA
printf("\e[H");
 
fb();
return 0;
}
EOF
} > "$0".tmp.c
 
########################################
 
gcc -lm "${0}".tmp.c -o "${0}".tmp
r=$?
test "$r" = 0 && ./"${0}".tmp
 
 
########################################
# $ cat minigeo | grep -v "^$" | grep -v "^[#/]" | wc -l
# 103
# That's all, folks!

 Dovrebbe essere C , esiste un ambiente online di esecuzione?
 
 
Ce ne sono diversi, uno e' questo.
https://www.onlinegdb.com