Question- Write a function power ( a, b ), to calculate the value of a
raised to b.
Solution- Again a repeated question with approach. let's have a look at it's solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,power;
printf("Enter the required number and it's power\n");
scanf("%d%d",&num,&power);
powerfunc(num,power);
return 0;
}
powerfunc(int n,int p)
{
int i,ans=1;
for(i=1;i<=p;i++)
ans=n*ans;
printf("Answer=%d\n",ans);
}
raised to b.
Solution- Again a repeated question with approach. let's have a look at it's solution.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num,power;
printf("Enter the required number and it's power\n");
scanf("%d%d",&num,&power);
powerfunc(num,power);
return 0;
}
powerfunc(int n,int p)
{
int i,ans=1;
for(i=1;i<=p;i++)
ans=n*ans;
printf("Answer=%d\n",ans);
}
No comments:
Post a Comment