Write a program to find the power of a number.
Used Function
- #include<stdio.h>
- void power(int,int);
- void main()
- {
- int base, expo;
- printf("Enter the base : ");
- scanf("%d",&base);
- printf("Enter the exponent : ");
- scanf("%d",&expo);
- power(base, expo);
- }
- void power(int base, int expo)
- {
- int power=1;
- while(expo>0)
- {
- power=power*base;
- expo--;
- }
- printf("\nPower of the number is = %d", power);
- }
Recursion
- #include <stdio.h>
- int power(int base, int expo)
- {
- if(expo==0)
- return 1;
- else
- return (base*power(base, expo-1));
- }
- void main()
- {
- int base, expo;
- printf("Enter the base : ");
- scanf("%d", &base);
- printf("Enter the exponent : ");
- scanf("%d", &expo);
- printf("\nPower of the number is (%d^%d) = %d", base, expo, power(base, expo));
- }
একটি মন্তব্য পোস্ট করুন