supponendo che pippo (num_b) sia sempre "lungo" (il 10 vale come un carattere) quanto pesi (num_a)codice:<html> <head> <title>...</title> <script language="javascript" type="text/javascript"> var num_a='123105678910'; var num_b='10234567899'; var arr_a=new Array(); var arr_b=new Array(); var arr_axb=new Array(); function riempi_array(num,arr){ for (var j=0, k=0; k<num.length; k++){ if(num.charAt(k)=='0' && num.charAt(k-1)=='1') arr[j-1]='10' else { arr[j]=num.charAt(k); j++ } } } riempi_array(num_a,arr_a); riempi_array(num_b,arr_b); // riempi array prodotti; for (var k=0;k<arr_a.length;k++){ arr_axb[k]=parseInt(arr_a[k]*arr_b[k]) } </script> </head> <body> <script language="javascript" type="text/javascript"> document.write('a='+num_a+' b='+num_b+' <table border="1"><tr><th>a</th><th>b</th><th>axb</th></tr>'); for (var k=0;k<arr_axb.length;k++){ document.write('<tr><td>'+arr_a[k]+'</td><td>'+arr_b[k]+'</td><td>='+arr_axb[k]+'</td></tr>'); } document.write('</table>'); </script> </body> </html>
![]()

Rispondi quotando