Ответы пользователя по тегу Программирование
• ## Создать цикл по специальному условию?

@Gokilla Автор вопроса
Вот ответ и полный код программы
``````<script>
var c2=[],c3=[],c4=[],c5=[];
c2[0] = 0.4829629131445341;
c2[1] = 0.8365163037378077;
c2[2] = 0.2241438680420134;
c2[3] = -0.1294095225512603;
c3[0] = 0.3326705529500825;
c3[1] = 0.8068915093110924;
c3[2] = 0.4598775021184914;
c3[3] = -0.1350110200102546;
c3[4] = -0.0854412738820267;
c3[5] = 0.0352262918857095;
c4[0] = 0.2303778133088964;
c4[1] = 0.7148465705529154;
c4[2] = 0.6308807679398587;
c4[3] = -0.0279837694168599;
c4[4] = -0.1870348117190931;
c4[5] = 0.0308413818355607;
c4[6] = 0.0328830116668852;
c4[7] = -0.0105974017850690;
c5[0] = 0.1601023979741929;
c5[1] = 0.6038292697971895;
c5[2] = 0.7243085284377726;
c5[3] = 0.1384281459013203;
c5[4] = -0.2422948870663823;
c5[5] = -0.0322448695846381;
c5[6] = 0.0775714938400459;
c5[7] = -0.0062414902127983;
c5[8] = -0.0125807519990820;
c5[9] = 0.0033357252854738;
var sum=0,sum2=0;
for(var j=0;j<c2.length;j++)
{
sum+=c2[j]*Math.sqrt(2);
for(var m=Math.round(-(c2.length-1)/2);m<(c2.length-1)/2,j+2*m<c2.length;m++)
{
if(j+2*m>=0)
{
sum2+=2*c2[j]*c2[j+2*m];
document.write("Value c2:"+(j+2*m)+ "<br>");
}
}
document.write("Value c2 coeff:"+c2[j]+ "<br>");
}
document.write("Value c2 coeff sum:"+sum+ "<br>");
document.write("Value c2 coeff sum2:"+sum2+ "<br>");
sum=0,sum2=0;;
for(var j=0;j<c3.length;j++)
{
sum+=c3[j]*Math.sqrt(2);
document.write("Value c3 coeff:"+c3[j]+ "<br>");
for(var m=Math.round(-(c3.length-1)/2);m<(c3.length-1)/2,j+2*m<c3.length;m++)
{
if(j+2*m>=0)
{
sum2+=2*c3[j]*c3[j+2*m];
document.write("Value c3:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value c3 coeff sum:"+sum+ "<br>");
document.write("Value c3 coeff sum2:"+sum2+ "<br>");
sum=0,sum2=0;
for(var j=0;j<c4.length;j++)
{
sum+=c4[j]*Math.sqrt(2);
document.write("Value c4 coeff:"+c4[j]+ "<br>");
for(var m=Math.round(-(c4.length-1)/2);m<(c4.length-1)/2,j+2*m<c4.length;m++)
{
if(j+2*m>=0)
{
sum2+=2*c4[j]*c4[j+2*m];
document.write("Value c4:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value c4 coeff sum:"+sum+ "<br>");
document.write("Value c4 coeff sum2:"+sum2+ "<br>");
sum=0,sum2=0;;
for(var j=0;j<c5.length;j++)
{
sum+=c5[j]*Math.sqrt(2);
document.write("Value c5 coeff:"+c5[j]+ "<br>");
for(var m=Math.round(-(c5.length-1)/2);m<(c5.length-1)/2,j+2*m<c5.length;m++)
{
if(j+2*m>=0)
{
sum2+=2*c5[j]*c5[j+2*m];
document.write("Value c5:"+(j+2*m)+ "<br>");
}
}
}
document.write("Value c5 coeff sum:"+sum+ "<br>");
document.write("Value c5 coeff sum2:"+sum2+ "<br>");
console.log("echo");
</script>``````
Ответ написан