Home  • Programming • JavaScript

Solve the following summation of series using JavaScript?

Code Solutions [4384] 1=1 1+2=3 1+2+3=6 1+2+3+4=10 ... 1+2+3+4+...+n=n*(n+1)/2
 <script>
  var n=6;
  for(i=1;i<=n;i++){   
      var total=0;
      for(j=1;j<=i;j++){
        document.write(j)
        if(j<i){            
         if(i!=1){  
            document.write("+")    
         }
        }
        total+=j;
      }

    document.write("="+total+"<br>");
  }
</script> 

Comments 0


Share

Copyright © 2024. Powered by Intellect Software Ltd