10 lung = 130 : n=6
20 ndati=0 : for i=0 to n : dato(i)=i : k=i : gosub 1000 : freq(i)=cb*((1/8)^i)*((7/8)^(n-i)) : ndati=ndati+freq(i) : next
40 print "" : tot=0 : for i=0 to n : tot=tot+dato(i)*freq(i) : next
50 media=tot/ndati : print "totale = ";tot, "media = "; media
60 tot=0 : for i=0 to n : tot=tot+(dato(i)-media)^2*freq(i) : next
70 print "varianza = "; tot/ndati, "sqm = "; sqr(tot/ndati)
80 print : for i=0 to n-1
90 p = INT(freq(i)/tot*lung+0.5)
100 s="|" : for k=1 to p : s=s+"#" : next
105 X=freq(i) : N=4 : gosub 200
110 print s + "  " + X1 : next
120 end
1000     ' Calcolo di C(n,k)
1010 if k > n/2 then k = n-k
1020 cb=1 : for j=0 to k-1 : cb=cb*(n-j)/(j+1) : next
1030 return
2000      ' Arrotondo X al posto N e metto esito in X1
2010 w=1 : for I=1 to abs(N) : w=w*10 : next
2020 if N>=0 then X1=int(X*w+1/2)/w else X1=int(X/w+1/2)*w
2030 return

totale = 0.75   media = 0.75
varianza = 0.65625   sqm = 0.8100925873009825

|#########################################################################################  0.4488
|############################################################################  0.3847
|###########################  0.1374
|#####  0.0262
|#  0.0028
|  0.0002


10 lung = 130 : n=6
20 ndati=0 : for i=0 to n : dato(i)=i : k=i : gosub 1000 : freq(i)=cb*((1/8)^i)*((7/8)^(n-i)) : ndati=ndati+freq(i) : next
40 print "" : tot=0 : for i=0 to n : tot=tot+dato(i)*freq(i) : next
50 media=tot/ndati : print "totale = ";tot, "media = "; media
60 tot=0 : for i=0 to n : tot=tot+(dato(i)-media)^2*freq(i) : next
70 print "varianza = "; tot/ndati, "sqm = "; sqr(tot/ndati)
80 print : for i=0 to n-1
90 p = INT(freq(i)/tot*lung+0.5)
100 s="|" : for k=1 to p : s=s+"#" : next
105 X=freq(i) : N=4 : gosub 200
110 print s + "  " + X1 : next
120 end
1000     ' Calcolo di C(n,k)
1010 if k > n/2 then k = n-k
1020 cb=1 : for j=0 to k-1 : cb=cb*(n-j)/(j+1) : next
1030 return
2000      ' Arrotondo X al posto N e metto esito in X1
2010 w=1 : for I=1 to abs(N) : w=w*10 : next
2020 if N>=0 then X1=int(X*w+1/2)/w else X1=int(X/w+1/2)*w
2030 return


10 input "x positvo "; x
20 input "posto a cui arrotondare "; p
30 K = x : P = p
35 gosub 1000 : print W
40 goto 10
1000 ' W = arrotondamento di K alla cifra di posto P (es.: 2 centinaia, -3 millesimi)
1010 W = int(K*(10^-P)+1/2)*(10^P) : return

1010 W = int(K/(10^P)+1/2)*(10^P) : return

10 INPUT "x = ";x
20 PRINT "valore assoluto di x = "; ABS(x)
30 PRINT "parte intera di x = "; INT(x)
40 PRINT "arrotondamento agli interi = "; INT(x+1/2)
50 PRINT "arrotondamento ai centesimi = "; INT(x*100+1/2)/100
60 PRINT "arrotondamento alle centinaia x = "; INT(x/100+1/2)*100
70 GOTO 10


function Arro(p,x)
{ if(x==0) {u=0} else {
  if(x<0) {S=-1} else {S=1}; x = Math.abs(x);
  odg = Math.floor(Math.log(x)/Math.log(10))
  m = Math.pow(10,p); u = S*Math.round(x*m)/m }  }


10 input "x positvo "; x
20 input "posto a cui arrotondare "; p
30 K = x : P = p
35 gosub 1000 : print W
40 goto 10
1000 ' W = arrotondamento di K alla cifra di posto P (es.: 2 centinaia, -3 millesimi)
1010 W = int(K*(10^-P)+1/2)*(10^P) : return

10 input "x positvo "; x
20 input "posto a cui arrotondare "; p
30 K = x : P = p
35 gosub 1000 : print W
40 goto 10
1000 ' W = arrotondamento di K alla cifra di posto P (es.: 2 centinaia, -3 millesimi)
1010 W = int(K*(10^-P)+1/2)*(10^P) : return


10 x = 123.456 : n=-2
20 print int(x*(10^(-n))+1/2)*(10 ^ n)


10 x = 123.45678 : n=-3
20 print int(x*(10*10*10)+1/2)/(10*10*10)

123.457

-----------------------------------------------
10 input "x = "; x : input "n = "; n
20 N = n : X = x : gosub 100 : print X1
30 goto 10
100 K=1: if(N>=0) then for i=1 to N: K=K*10: next
110 if(N<0) then for i=1 to -N: K=K*10: next
120 if(N>=0) then X1=int(X*K+1/2)/K else X1=int(X/K+1/2)*K
130 return

----------------------------------------------

10 input "x = "; x : input "n = "; n
20 if n >= 0 then gosub 100 else gosub 200
30 print x1
40 goto 10
100 k=1 : for i=1 to n : k=k*10 : next
110 x1=int(x*k+1/2)/k
120 return
200 k=1 : for i=1 to -n : k=k*10 : next
210 x1=int(x/k+1/2)*k
220 return
OK!
-----------------------------------------

10 input "x = "; x : input "n = "; n
20 gosub 100 : print x1
30 goto 10
100 w=1 : for i=1 to abs(n) : w=w*10 : next
110 if n>=0 then x1=int(x*w+1/2)/w else x1=int(x/w+1/2)*w
120 return





100 k=x : for i=1 to 3 : k=k*10 : next
110 k=int(k+1/2)
120 for i=1 to 3 : k=k/10 : next
130 print k





10 x = 123.456 : n=-2
20 print int(x*(10*10)+1/2)/(10*10)

10 input "x positvo "; x
20 input "posto a cui arrotondare "; p
30 K = x : P = p
35 gosub 1000 : print W
40 goto 10
1000 ' W = arrotondamento di K alla cifra di posto P (es.: 2 centinaia, -3 millesimi)
1010 W1=K : if P>=0 then for i=1 to P : W1=W1*10: next : W1=int(W1+1/2) : for i=1 to P : W1=W1/10: next
1020 W=W1 : return


W = int(K*(10^-P)+1/2)*(10^P) : return