TASK-
Write a function pow() which takes two integer parameters a and n and returns nth power of a, write a program to use this function.
CODE:
#include <stdio.h>
int pow(int n,int a);
int main(){
int n,a,p;
printf("Enter the number and its power : ");
scanf("%d%d",&n,&a);
p=pow(n,a);
printf("\n %d to the %d is %d",n,a,p);
getchar();
return 0;
}
int pow(int n,int a)
{
int i,p=1;
for (i=1;i<=a;i++)
{
p=p*n; //p=1,then if n=2, which follow p=1,then p=p*n
}
return p;
}
Nice Work Brother ! Highly Appreciated Keep it up
ReplyDeleteI like it
ReplyDelete