Tuesday, April 6, 2021

18.17. Write a function that gets two positive integers(a, b) and returns a to the power b.

#include<stdio.h>
#include<conio.h>
long Power(int a, int b)
{

long p=1;
int i;
for(i=1;i<=b;i++)
p=p*a;
return p;
}
void main ()
{
int a,b;
clrscr();
printf("Enter any positive integer: ");
scanf ("%d", &a);
printf("Enter any positive integer: ");
scanf ("%d", &b);
printf("%d to the 
Power of %d=%d",a,b,Power(a,b)) ;
getch ();
}

No comments:

Post a Comment