Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Dedicated Hosting Superb Internet

simplilearn big data and analytics

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to calculate long value of x to the power of y in C

Directory of Wholesale Companies and Dropship Suppliers | SaleHoo

9 views
asked Sep 1 by avibootz

1 Answer

0 votes
#include <stdio.h>
#include <math.h>
#include <fenv.h>
#include <errno.h>

int main(void)
{
    double power, sum = 0;

    printf("calculate: 5^2 + 5^3 + 5^4 + 5^5 + 5^6\n");

    for (int i = 2; i <= 6; i++) 
    {
        errno = 0;
        feclearexcept(FE_ALL_EXCEPT);
        power = powl(5, i);
        if (fetestexcept(FE_DIVBYZERO | FE_INVALID  | FE_OVERFLOW | FE_UNDERFLOW)) 
            perror("Math Error");
        sum += power;
        printf("sum = %g\n", sum);
    }

    return 0;
}

   
/*
run:
 
calculate: 5^2 + 5^3 + 5^4 + 5^5 + 5^6
sum = 25
sum = 150
sum = 775
sum = 3900
sum = 19525

*/

 




answered Sep 1 by avibootz
...