Friday, 30 November 2012

How to get power without library (math.h) function


Write this program in Turbo C++ or DEV C++ and Compile/Run it.

#include<stdio.h>
#include<conio.h>
int asif(int x,int y);
int main(){
int n,p,out;
printf("Enter Number:");
scanf("%d",&n);
printf("Enter Power");
scanf("%d",&p);
out=asif(n,p);
printf("Power is %d",out);
getch();
return 0;
}
int asif(int x,int y){
    int i,p=1;
    for(i=0; i<y; i++){
             p=p*x;
    }
    return p;
}

Otuput:

Enter Number:5
Enter Power:3
Power is 125

Thanks for watching...
Comment it.

No comments:

Post a Comment