bsc

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

lucproblem007.c (1106B)


      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 /* Two numbers are entered through the keyboard. Write a program to
      8 find the value of one number raised to the power of another */
      9 /* Let Us C, Chap - 5, Page - 84, Problem 5.3 */
     10 
     11 #include <stdio.h>
     12 int main()
     13 {
     14     double num, result;
     15     int power, i = 1;
     16     printf("Enter the numbers in 'num^power' format : ");
     17     // checking if the input is valid or not
     18     if (scanf("%lf^%d", &num, &power) != 2)
     19     {
     20         printf("\nPlease enter numbers.");
     21         return 1;
     22     }
     23      // result for the negetive input
     24     if (power < 0)
     25     {
     26         printf("\nPlease use a positive number as power.");
     27         return 1;
     28     }
     29     //  Hard codded result for input '0' (zero)
     30     if (power == 0)
     31     {
     32         printf("\n%g to the power of %d is : 1", num, power);
     33         return 0;
     34     }
     35     result = num;
     36     while (i <= power - 1)
     37     {
     38         result = result * num;
     39         i++;
     40     }
     41     printf("\n%g to the power of %d is : %g", num, power, result);
     42     return 0;
     43 }
© 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