bsc

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

lucproblem015.c (1481B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Write a program that defines a function that calculates power of one
      9 number reaised to another and factorial value of a number in one cell. */
     10 /* Let Us C, Chap - 9, Page 159, Problem 9.2 */
     11 
     12 #include <stdio.h>
     13 
     14 void bothPowerFactorial(double, int, int, double *, long long *);
     15 
     16 int main()
     17 {
     18     double a, resultPower;
     19     int b, factN;
     20     long long resultFactorial;
     21     printf("Enter a and b for calculating a raised to b: ");
     22     scanf("%lf %d", &a, &b);
     23     printf("Enter number to calculate the factorial: ");
     24     scanf("%d", &factN);
     25     if (b < 0 || factN < 0)
     26     {
     27         printf("\nOnly non-negative integer is allowed as input of b and factorial.");
     28         return 1;
     29     }
     30     bothPowerFactorial(a, b, factN, &resultPower, &resultFactorial);
     31     printf("\n%g Raised to %d: %g"
     32            "\nFactorial of %d: %lld",
     33            a, b, resultPower, factN, resultFactorial);
     34     return 0;
     35 }
     36 
     37 void bothPowerFactorial(double a, int b, int n, double *resultPower, long long *resultFactorial)
     38 {
     39     double tempResultPower = 1;
     40     long long tempResultFactorial = 1;
     41     int i;
     42 
     43     for (i = 1; i <= b; i++)
     44         tempResultPower *= a;
     45 
     46     for (i = 1; i <= n; i++)
     47         tempResultFactorial *= i;
     48 
     49     *resultPower = tempResultPower;
     50     *resultFactorial = tempResultFactorial;
     51 }
© 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