英文:
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 <stdio.h>
#include <math.h>
int main()
{
    int A,B;
    int C=pow(A,B);
    printf("To find power please enter values of A and B \n");
    printf( "Please enter value of A: \n");
    scanf("%d",&A);
    printf("Please enter value of B: \n");
    scanf("%d",&B);
    printf("The power of A and B is : %d",C);
    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("The power of A and B is : %d",C);
Complete code
#include <stdio.h>
#include <math.h>
int main()
{
int A, B;
printf("To find power please enter values of A and B \n");
printf("Please enter value of A: \n");
scanf("%d", &A);
printf("Please enter value of B: \n");
scanf("%d", &B);
int C = pow(A, B);
printf("The power of A and B is : %d", 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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论