Easy Problem

This is a discussion on Easy Problem within the C Programming forums, part of the General Programming Boards category; Hey I am very new to C programming and I need help. I am trying to make a program using ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    9

    Easy Problem

    Hey I am very new to C programming and I need help.

    I am trying to make a program using the Do While loop only once to multiply all the even numbers from 1-10. Result being :3840

    I have been trying for a long time now and can't figure out how to keep the last integer that was used in the prior loop to multiply against the next one if that makes sense. If that doesn't, here is what I am trying to do:

    2X4X6X8X10 = 3840

    I keep trying to increment the variable num by tempNum(2) each loop but I cant figure out how to keep that # for the next loop so that I can multiply them in order. Can you help?

    Code:
    #include <stdio.h>
    
    void main(void)
    {
    
    int num, tempNum;
    
    tempNum = 2;
    do
    {
    
    num = num + tempNum;
    num = num * num;
    printf("Num = %d\n", num");
     
    }while(num<=10);
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >but I cant figure out how to keep that # for the next loop so that I can multiply them in order.
    Code:
    tempNum = 2;
    num = 1;
    do
    {
        num *= tempNum;
        tempNum += 2;
        printf("Num = %d\n", num");
     
    } while(tempNum<=10);

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    9
    you rock my friend, I just wasn't thinking in the right terms. thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  2. Relatively easy math problem...
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-18-2005, 09:48 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  4. Math Problem....
    By NANO in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-11-2002, 04:37 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21