this program has raise a number to a given number but is not working.
printf(" enter the number:");
printf("\n enter the power:");
printf("the result is %d",c);
a program that raise a number to a given power
Post a Reply
|Oldest Newest Rating|
· June 21, 2015
· June 20, 2015
If you're a beginner I suggest use a while or for loop to do it. You'd now have to think the logic on how to do it yourself instead of using a predefined function.
Sure thousands of libraries are made to make programming life easier but logic is a part of what makes you a programmer so you have to practice and improve it.
Just a food for thought.
· June 20, 2015
if you actually want to get into making the pow function in c, then use something called recursion. you should make a method, pass in the base and power, and then in the method check if the power == 0 if it is return 1 otherwise multiply the base by itself and at the end of the function you can all the method, but power-- or decrementing the power by one everytime you go through the function.
· June 17, 2015
Here I fixed it for you.
Instead of the loop you could use "c = pow(a,b)" if you include the "math.h" library.
· June 11, 2015
you either have to import math.h and use the pow function which returns a float or use a loop to simulate it. C, C++, and Java do not have a built in operator like python and even in python thats not the operator you would use. so it would look like:
c = pow(a, b);
printf("the result is %f",c);
if you want to control how many decimal places are shown you can use "%.<number of decimal places>f" for example:
printf("the result is %.2f",c);
would only display 2 decimal places.
i really hope this helps.
One of the most popular languages of all time.
|Bucky Roberts Administrator|