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

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

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

问题

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

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

#include <stdio.h>
#include <math.h>

int main()
{
    int A, B; 
    int C = pow(A, B);
    printf("要查找的幂请输入 A 和 B 的值\n");
    printf("请输入 A 的值:\n");
    scanf("%d", &A);
    printf("请输入 B 的值:\n");
    scanf("%d", &B);
    printf("A 和 B 的幂是:%d", C);
    return 0;
}

不要翻译的部分已保留。

英文:

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.

#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main()
{
&#160; &#160; int A,B; 
&#160; &#160; int C=pow(A,B);
&#160; &#160; printf(&quot;To find power please enter values of A and B \n&quot;);
&#160; &#160; printf( &quot;Please enter value of A: \n&quot;);
&#160; &#160; scanf(&quot;%d&quot;,&amp;A);
&#160; &#160; printf(&quot;Please enter value of B: \n&quot;);
&#160; &#160; scanf(&quot;%d&quot;,&amp;B);
&#160; &#160; printf(&quot;The power of A and B is : %d&quot;,C);
&#160; &#160; return 0;
}

答案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);之前。

完整的代码

#include <stdio.h>
#include <math.h>

int main()
{
    int A, B;
    printf("要找到幂,请输入A和B的值\n");
    printf("请输入A的值:\n");
    scanf("%d", &A);
    printf("请输入B的值:\n");
    scanf("%d", &B);
    int C = pow(A, B);
    printf("A和B的幂是:%d", C);
    return 0;
}

标签"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

#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main()
{
    int A, B;
    printf(&quot;To find power please enter values of A and B \n&quot;);
    printf(&quot;Please enter value of A: \n&quot;);
    scanf(&quot;%d&quot;, &amp;A);
    printf(&quot;Please enter value of B: \n&quot;);
    scanf(&quot;%d&quot;, &amp;B);
    int C = pow(A, B);
    printf(&quot;The power of A and B is : %d&quot;, C);
    return 0;
}

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:

确定