Thread: summation in c

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Quote Originally Posted by master5001 View Post
    Look at my post, homeboy. tabstop merely corrected your assertion about how the += operator works.
    Ahh ok homeslice :P...this forum moves faster than abullet I can't keep up!

    Anyway, so in your code, you have used it within and without the parentheses...what is the difference between this, and just using it without?

  2. #17
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Quote Originally Posted by master5001 View Post
    Are you an SQL programmer, bertazoid? That is the sort of behavior tables exhibit.
    Nope, to tell the truth I've only ever used scripting languages before for various bits of software, and have been programming for a mere month or so as it's part of my electronics degree....I will have to learn assembly and MATLAB later too, as well as a ........ loads of advanced maths like fourier/laplace transforms. :/

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Well my hats off to you, bud. That is certainly a noble profession. You will have fun with assembly I know I like playing with it. Maybe you can help in my plight to get MathML extentions supported on the forum.

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Why thank you, I really want to learn assembly, as it's quite relevant to programming microcontrollers, which is more along the lines of what I'll be doing (rather than software development for OS's).

    I've never heard of math ML, but i will certainly invite you on a new plight to get LaTeX...as I have used it for a while on maths forums, and it is very powerful and easy to use, and not that hard to implement. (I think)

    I looked at the wiki on math ml and it says:

    The expression ax2 + bx + c could be represented as

    <apply>
    <plus/>
    <apply>
    <times/>
    <ci>a</ci>
    <apply>
    <power>
    <ci>x</ci>
    <cn>2</cn>
    </power>
    </apply>
    </apply>
    <apply>
    <times/>
    <ci>b</ci>
    <ci>x</ci>
    </apply>
    <ci>c</ci>
    </apply>
    In LaTeX, this is simply [math]ax^2+bx+c[/math]

  5. #20
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    LaTeX is fine by me I have used it before. There are times when I am trying to explain a mathematical concept or write a function that does an equation, and have no visually appealing way to express the equation.

    The end result: Summation = for loop.

    Or similar.

  6. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Also, another question, could I declare variables within the for loop like so:

    Code:
    float sum=0.0;
    for(x=0;x<=5;x++)
    {
      float xi=a+(b*x);
      float function = xi*xi;
      sum+=function;
      continue;
    }
    printf("sum of series = %f\n",sum)
    ...so that even though 'xi' and 'function' would be reset on each iteration, the code would still work the same?....I'd like to do this just to break up the code a bit, and it looks a bit neater, and easier for me to keep track of.

    Also, does 'continue;' just tell the loop to continue? Silly question, but I was under the impreson it would continue anyway until x<=5.

  7. #22
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Quote Originally Posted by master5001 View Post
    LaTeX is fine by me I have used it before. There are times when I am trying to explain a mathematical concept or write a function that does an equation, and have no visually appealing way to express the equation.

    The end result: Summation = for loop.

    Or similar.
    I know what you mean, i hate trying to read things like int^b_a 2x*e(2-3x)/[x^3-2x+5] dx lol

  8. #23
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah continue just skips back to the beginning of the loop. Don't use it like that, however. Its only handy if you need to conditionally leap ahead one iteration.

    Yes, it is perfectly legal to declare variables like that. Its prefered by many since it makes it clearer what each variable is used for.

  9. #24
    Registered User
    Join Date
    Oct 2008
    Posts
    110

    Thumbs up

    Ok thats good, well thanks alot for all your help! I'll try and re-run my program.

    see you soon on the forums!

  10. #25
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Wait... before you run off. Vote!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sine series summation
    By kashya in forum C Programming
    Replies: 3
    Last Post: 12-17-2008, 08:00 PM
  2. partially summation
    By joerg in forum C Programming
    Replies: 0
    Last Post: 11-23-2007, 10:47 AM
  3. Help With Simple Summation...
    By TOPFLOR in forum C Programming
    Replies: 19
    Last Post: 08-09-2006, 10:50 AM
  4. Summation of an array using pointers
    By therminator53 in forum C Programming
    Replies: 3
    Last Post: 11-30-2003, 01:23 AM