質問する質問する
 

回答済みHelp with function

  • 2009年11月4日 5:17carl89_P ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hi im trying to write pow function, i know that i can use <math.h> at top of my code but the deal is i cannot use that in my code so i need to write a function  for pow and its get call in int main(), its taking value from user and givinf out put help,plz
    thz

回答

  • 2009年11月4日 15:20carl89_P ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    Hi AS u said i know how to write it by pencil,

    pow(x,y)
    X^y = answer

    2^3 = 8

    but in c++ we cannot use "  ^ " sign so is there anything that can replace that " ^ " in c++.
    thx
    • 回答としてマークcarl89_P 2009年11月4日 19:10
    •  

すべての返信

  • 2009年11月4日 5:37Brian MuthMVPユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    I hope you are aware we are not here to give answers to homework assignments. However, I'm guessing the teacher wants you to use other functions in place of pow(). exp() and ln() come to mind.
  • 2009年11月4日 5:41Scott McPhillipsMVPユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Do you know how to do it with a pencil?  That is the first step.  You can't write code without an algorithm.

    Tell us or show us what you have so far.  And ask a specific question.



  • 2009年11月4日 15:20carl89_P ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答済み
    Hi AS u said i know how to write it by pencil,

    pow(x,y)
    X^y = answer

    2^3 = 8

    but in c++ we cannot use "  ^ " sign so is there anything that can replace that " ^ " in c++.
    thx
    • 回答としてマークcarl89_P 2009年11月4日 19:10
    •  
  • 2009年11月4日 15:45jinzai ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答の候補
    ...and that is how it is done. If what you wrote does not make it any clearer, perhaps you should write it out using words, and not math symbols.

    So, what does pow do? It takes two arguments, one is the number in question, the other is going to be the number of times that you multiply the first number by itself to achieve the desired result. Loops work well for this. You also need to return a result.

    So, you have a basic for loop to write, if you choose to do it that way. You will need to choose an appropriately large return type, because you are writing a function that could potentially return a very large integer. You will need to accept two integers as parameters.
    • 回答の候補に設定KEERV 2009年11月11日 9:18
    •