Power function [pow()] always giving a ZERO as result

huangapple go评论89阅读模式
英文:

Power function [pow()] always giving a ZERO as result

问题

Power function always giving a zero(0) as result no matter the input.

我学习了幂函数,但无论输入什么都会得到零(0)作为结果。

  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5. int A, B;
  6. int C = pow(A, B);
  7. printf("要查找的幂请输入 A 和 B 的值\n");
  8. printf("请输入 A 的值:\n");
  9. scanf("%d", &A);
  10. printf("请输入 B 的值:\n");
  11. scanf("%d", &B);
  12. printf("A 和 B 的幂是:%d", C);
  13. return 0;
  14. }

不要翻译的部分已保留。

英文:

Power function always giving a zero(0) as result no matter the input.

I am learning the power function, but it doesn't work.please help.

  1. #include &lt;stdio.h&gt;
  2. #include &lt;math.h&gt;
  3. int main()
  4. {
  5. &#160; &#160; int A,B;
  6. &#160; &#160; int C=pow(A,B);
  7. &#160; &#160; printf(&quot;To find power please enter values of A and B \n&quot;);
  8. &#160; &#160; printf( &quot;Please enter value of A: \n&quot;);
  9. &#160; &#160; scanf(&quot;%d&quot;,&amp;A);
  10. &#160; &#160; printf(&quot;Please enter value of B: \n&quot;);
  11. &#160; &#160; scanf(&quot;%d&quot;,&amp;B);
  12. &#160; &#160; printf(&quot;The power of A and B is : %d&quot;,C);
  13. &#160; &#160; return 0;
  14. }

答案1

得分: 3

You're setting the value of C before you assign the A and C values.

int C = pow(a, b);放在运行printf("The power of A and B is : %d",C);之前。

完整的代码

  1. #include <stdio.h>
  2. #include <math.h>
  3. int main()
  4. {
  5. int A, B;
  6. printf("要找到幂,请输入A和B的值\n");
  7. printf("请输入A的值:\n");
  8. scanf("%d", &A);
  9. printf("请输入B的值:\n");
  10. scanf("%d", &B);
  11. int C = pow(A, B);
  12. printf("A和B的幂是:%d", C);
  13. return 0;
  14. }

标签"powershell"似乎是随机的,应该将标签设置为您正在使用的编程语言。

英文:

You're setting the value of C before you assign the A and C values.

Put int C = pow(a, b); right before you run printf(&quot;The power of A and B is : %d&quot;,C);

Complete code

  1. #include &lt;stdio.h&gt;
  2. #include &lt;math.h&gt;
  3. int main()
  4. {
  5. int A, B;
  6. printf(&quot;To find power please enter values of A and B \n&quot;);
  7. printf(&quot;Please enter value of A: \n&quot;);
  8. scanf(&quot;%d&quot;, &amp;A);
  9. printf(&quot;Please enter value of B: \n&quot;);
  10. scanf(&quot;%d&quot;, &amp;B);
  11. int C = pow(A, B);
  12. printf(&quot;The power of A and B is : %d&quot;, C);
  13. return 0;
  14. }

The tag powershell seems random, you should have the tag set to the language that you're using.

答案2

得分: -2

Int C=pow(A,B);
printf("A 和 B 的幂是:%d",C);
基本上是将它从上面移到下面。
而且它奏效了!

英文:

I just now moved the
Int C=pow(A,B);
line just before
printf("The power of A and B is : %d",C);
Basically moved it from top to bottom.
And it worked!

huangapple
  • 本文由 发表于 2023年3月21日 03:29:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75794526.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定