Write a program to find the power of a number

Write a program to find the power of a number.
Used Function
  1. #include<stdio.h>
  2. void power(int,int);
  3.  
  4. void main() 
  5. {
  6.     int base, expo;
  7.     printf("Enter the base : ");
  8.     scanf("%d",&base);
  9.     
  10.     printf("Enter the exponent : ");
  11.     scanf("%d",&expo);
  12.     
  13.     power(base, expo);
  14. }
  15.  
  16. void power(int base, int expo)
  17. {
  18.     int power=1;
  19.     while(expo>0)
  20.     {
  21.         power=power*base;
  22.         expo--;
  23.     }
  24.     printf("\nPower of the number is = %d", power);
  25. }

Recursion
  1. #include <stdio.h>
  2.  
  3. int power(int base, int expo)
  4. {
  5.     if(expo==0)
  6.         return 1;
  7.     else 
  8.         return (base*power(base, expo-1));
  9. }
  10.  
  11. void main()
  12. {
  13.     int base, expo;
  14.     printf("Enter the base : ");
  15.     scanf("%d", &base);
  16.     
  17.     printf("Enter the exponent : ");
  18.     scanf("%d", &expo);
  19.     
  20.     printf("\nPower of the number is (%d^%d) = %d", base, expo, power(base, expo));
  21. }

একটি মন্তব্য পোস্ট করুন