Hey guys, I'm new to C programming, taking a course for EE.
This is the question: C does not have an exponentiation operator. Write a C program that allows the user to enter the base a and the exponent b and prints the value of (a^b). You may not use any library functions other than printf and scanf. Assume b is an integer.
So I have my program but when you input a and b, it seems like it hang ups, no output. When you press enter many times, it doesn't do anything. Only when you input something (when you are not suppose), does it display the printf statement.
Can anyone help me out? thanks
here is the code:
Code:
#include <stdio.h>
int main ()
{
int b,i;
float a,c;
printf("\nEnter base value a: ");
scanf("\n%f", &a);
printf("\nEnter exponent value b: ");
scanf("\n%i\n", &b);
c=1;
i=1;
while(i<=b)
{
c*=a;
i++;
}
printf("\nThe answer is %.2f", c);
return(0);
}