I were asked to c-program to accept two variables and print the answer when second variable is raised to the power of first variable. So I coded,
#include<stdio.h>
#include<math.h>
int x,y;
int main()
{
scanf("%d %d",&x,&y);
printf("%d",pow(x,y));
}
It should be working right? But it doesn't! So I done
#include<stdio.h>
#include<math.h>
int x,y;
int main()
{
scanf("%d %d",&x,&y);
int u=pow(x,y);
printf("%d",u);
}
Then it worked. i.e for the inputs like x=10 y=3
the output for the first snippet, was 11829309 something I don't remember.
But the second one results correctly as 1000.
Please, tell why this happened?