power of a number

How can i make the power of a number???
I just tried x^2 but it doesn't work. Is the problem in the sign?

Use the pow function from cmath: http://www.cplusplus.com/reference/cmath/pow/

x = pow(x, 2);
For really small powers, you can also just multiply it by itself:

x = x * x;
I hope that it would be helpful through an example -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<stdio.h>
#include<math.h>

int main(void)
{
    int number,power,answer;
    printf("\n enter the number :  ");
    scanf("%d",&number);
    printf("\n enter the power of the number :  ");
    scanf("%d",&power);
    answer=pow(number,power);
    printf("\n the answer is :  %d",answer);
    return 0;
}
Topic archived. No new replies allowed.