this program is used to count nm .this program heart of this program is power function.This function is defined before main function Without defining it will show error when it is compiled.Let us see an example based on this program.For example,210 is 1024.In power function we have defined variable answer will count total answer.At first we have answer=x means the value or base number entered by user is x equals to answer then for loop is used to continue multiplying till power we wants.In above case x=2 is base and power=10 and answer of this is 2*2*2*2*2*2*2*2*2*2=1024.The program dies same thing and at last program will return value of answer which we wants.Now let us see program.
Program:
#include<stdio.h>
#include<conio.h>
long power(long,long);
main()
{
long n,ans,pow;
clrscr();
printf("Enter number: ");
scanf("%ld",&n);
printf("\nEnter power: ");
scanf("%ld",&pow);
ans=power(n,pow);
printf("\n%ld power %ld is %ld",n,pow,ans);
getch();
}
long power(long x,long y)
{
long temp,answer;
answer=x;
for(temp=1;temp<y;temp++)
{
answer=answer*x;
}
return answer;
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
long power(long,long);
main()
{
long n,ans,pow;
clrscr();
printf("Enter number: ");
scanf("%ld",&n);
printf("\nEnter power: ");
scanf("%ld",&pow);
ans=power(n,pow);
printf("\n%ld power %ld is %ld",n,pow,ans);
getch();
}
long power(long x,long y)
{
long temp,answer;
answer=x;
for(temp=1;temp<y;temp++)
{
answer=answer*x;
}
return answer;
}
Output:
