Alright im trying to write a fairly simple c program that will accept input from the user for both a number and a power to raise it to then display the result, it works up to the input part but the result is always some crazy number, im looking for any insight or methods to solve this solution, and please dont be vague because my instructor couldn't even find my error.
#include <stdio.h>
#include <stdlib.h>
/* homework 5.19 Author: Jeremy Villanueva */
/*begin Main Function */
int main(void)
{
/*initialize integers */
int pow;
int num;
long int res;
long int power(int,int);
/* enter the number and the power */
printf("\nEnter a number: ");
scanf("%d",&num);
printf("\nEnter power: ");
scanf("%d", &pow);
res= power(num,pow);
/*solution */
printf("\n%d to the power %d is: %ld\n",num,pow,res);
system("PAUSE");
return 0;
}
int i=1;
long int sum=1;
long int power(int num,int pow){
if(i<=pow){
sum=sum*num;
for ( i = 1; i < pow; i++);
}
return (power);
} /* end main function */
output
Enter a number: 3
Enter power: 5
3 to the power 5 is: 4199233
Press any key to continue . . .