Why is my power operator (^) not working?

2018-12-31 17:02发布

#include "stdio.h"
#include "math.h"

void main(void)
{
    int a;
    int result;
    int sum=0;
    printf("Enter a Number : ");
    scanf("%d",&a);
    for(int i=1;i<=4;i++)
    {
        result = a^i;

        sum =sum+result;
    }
    printf("%d\n",sum);
}

I don't know why this '^' is not working as power.

标签: c
7条回答
不流泪的眼
2楼-- · 2018-12-31 17:31

You actually have to use pow(number, power);. Unfortunately, carats don't work as a power sign in C. Many times, if you find yourself not being able to do something from another language, its because there is a diffetent function that does it for you.

查看更多
登录 后发表回答