473,466 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

shortenin

29 New Member
how can i shorten this to use only ONE(1) for loop??

Expand|Select|Wrap|Line Numbers
  1.   for(i=1;i<=n_value;i++){
  2.     cout<<"Value "<<i<<" = ";
  3.     cin>>input2[i];
  4.     total=input2[i]+ total;
  5.     avg =total/i;
  6. }
  7.     cout<<"Average of inputs = "<<avg<<endl;
  8.  
  9.     for(i=1;i<=n_value;i++){
  10.     value_average = input2[i]-avg;
  11.     power = pow(value_average,2);
  12.     total2 = total2 + power;
  13. }
Apr 9 '07 #1
1 1158
JosAH
11,448 Recognized Expert MVP
Have a look at this thread.

kind regards,

Jos
Apr 9 '07 #2

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.