- #include<stdio.h>
- #include<conio.h>
- int main() {
- int pow,no;
- long int res;
- long int power(int,int);
- printf("Enter a number: ");
- scanf("%d",&no);
- printf("\n Enter power: ");
- scanf("%d",&pow);
- res=power(no,pow);
- printf("\n%d to the power %d is: %ld",no,pow,res);
- return 0;
- }
- int i=1;
- long int sum=1;
- long int power(int num,int pow) {
- if(i<=pow) {
- sum=sum*no;
- power(no,pow-1);
- } else
- return sum;
- }
OUTPUT:
Enter a number: 5
Enter power: 2
5 to the power 2 is: 25
No comments:
Post a Comment