Thread: Another urgent help, plz reply fast

  1. #1
    Registered User
    Join Date
    Feb 2002

    Another urgent help, plz reply fast

    Ok, here is another question I got confused in the exam paper. As far as I know, to calculate some power of a number is like this

    pow (x,y)

    But then, the question mentions about the while repetition. How to end it? Or what is the while (condition) in this case? Someone help me here again plz. And reply fast cuz I got programming exam to tomorrow and i need to know how this question is done. (The question is below here)


    (Exam Question): Write a C program that calculates x to the y power. The program should have a while repetition control structure.(5 marks)

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    The pow() function is raises x to the y, you can also raise x to the y by multiplying x by x, y times. Use that.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Feb 2002

    Exclamation aha, ok, how bout while condition?

    ok, the pow part i understood, but what about the while condition. That is the part in the exam question that confuses me this most. I mean, i dont know what the while (condition) is. how should it be written?

  4. #4
    Registered User
    Join Date
    Dec 2001
    you can also creat a for loop .. here is how i did it...

    case '^':


    for(i=0; i<y; i++)

    result *=x;

    printf("answer = %d\n\n",result);


  5. #5
    so if y = 5 you would do this:-

    x * x * x * x * x

    With a while loop you should look at when you want to stop executing and then make sure the condition only becomes false at that point,

    e.g. here you want to stop executing after you have multiplied x by itself 5 times:

    while(i < 5){
    x = x*x;
    return x;

    where i<5 means 'while i < 5 do this'

    i.e. i=5 means it will no longer loop

    So to get this to work with y you could just substitute 5 with y.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. regarding Nth Power of a Number
    By Shameer in forum C++ Programming
    Replies: 8
    Last Post: 08-11-2010, 10:44 PM
  2. display the contents of all the files
    By Tintu in forum C Programming
    Replies: 8
    Last Post: 10-08-2007, 12:17 AM
  3. Quick Reply or Normal Reply
    By Thantos in forum A Brief History of
    Replies: 6
    Last Post: 05-18-2004, 12:49 PM
  4. urgent...experts pls reply
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-03-2002, 12:34 PM
  5. Need Help quick reply plz
    By playboy1620 in forum C Programming
    Replies: 1
    Last Post: 04-11-2002, 11:12 AM