bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

lucproblem012.c (725B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a Function power(a, b), to calculate the value of a raised to b */
      8 /* Let Us C, Chap - 8, Page - 141, Problem 8.2 */
      9 
     10 #include <stdio.h>
     11 
     12 double power(double, int);
     13 
     14 double power(double a, int b)
     15 {
     16     if (b == 0)
     17         return 1;
     18     double res = 1;
     19     int i;
     20     if (b > 0)
     21         for (i = 1; i <= b; i++)
     22             res *= a;
     23     return res;
     24 }
     25 
     26 int main()
     27 {
     28     double a, result;
     29     int b;
     30     printf("Enter the value and the power (Format A^B) : ");
     31     scanf("%lf^%d", &a, &b);
     32     result = power(a, b);
     33     printf("Result of %g^%d = %g", a, b, result);
     34     return 0;
     35 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror