Answers for "power function in c without pow"

C
2

power function in c without pow

// power function in c without pow
#include <stdio.h>
double mypow(double base, double power);
int main()
{

  int base, exponent;
  printf("Enter Base: ");
  scanf("%d", &base);
  printf("Enter Exponent: ");
  scanf("%d", &exponent);
  printf("%d raised to the power %d = %0.2lf\n", base, exponent, mypow(base, exponent));
  return 0;
}
double mypow(double base, double power)
{
    double result = 1;
    if (power >= 0)
    {

        while (power--)
        {
            result = result * base;
        }

        return result;
    }
    else if (power < 0)
    {
        while (power++)
        {
            result = result * base;
        }
        return 1 / result;
    }
}
Posted by: Guest on July-27-2021
0

Write a Program to find exponential without using pow() method

#include <stdio.h>
int main() {
    int base, exp;
    long long result = 1;
    printf("Enter a base number: ");
    scanf("%d", &base);
    printf("Enter an exponent: ");
    scanf("%d", &exp);

    while (exp != 0) {
        result *= base;
        --exp;
    }
    printf("Answer = %lld", result);
    return 0;
}
Posted by: Guest on July-31-2020
3

power func in c

The function pow() is used to calculate the power raised 
to the base value. It takes two arguments. It returns the
power raised to the base value. It is declared in 
“math.h” header file.
Posted by: Guest on December-22-2019
0

pow not working c

gcc ... -lm ...
#include <math.h>
Posted by: Guest on March-24-2020

Code answers related to "C"

Browse Popular Code Answers by Language