Cod sursa(job #2589647)
| Utilizator | Data | 26 martie 2020 17:51:40 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.65 kb |
#include <stdio.h>
#include <stdlib.h>
float putere(float n,float exp,float counter,float aux)
{
if(exp==0)
return 1;
if(exp>0)
{
if(counter!=exp)
{
aux=aux*n;
return putere(n,exp,counter+1,aux);
}
}
else if(exp<0)
{
if(counter!=exp)
{
aux=aux*1.0/n;
return putere(n,exp,counter-1,aux);
}
}
return aux;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
float n,exp;
scanf("%f %f",&n,&exp);
printf("%g",putere(n,exp,0,1));
return 0;
}
