Pagini recente » Cod sursa (job #1364643) | Cod sursa (job #1250098) | Cod sursa (job #2005739) | Cod sursa (job #2303157) | Cod sursa (job #3134429)
#include <stdio.h>
#include <stdlib.h>
float exp_log_rec(int N, int P)
{
if(P < 0)
{
return exp_log_rec(1.0 / N, -P);
}
else if(P == 0)
{
return 1;
}
else if(P % 2 == 0)
{
return exp_log_rec(N*N, P/2);
}
else if(P % 2 == 1)
{
return N * exp_log_rec(N*N, P/2);
}
return 0;
}
int main(void)
{
int N, P, result;
FILE *fin;
FILE *fout;
if((fin = fopen("lgput.in","r"))==NULL)
{
printf("Eroare deschidere fisier\n");
exit(-1);
}
if((fout = fopen("lgput.out","w"))==NULL)
{
printf("Eroare deschidere fisier\n");
exit(-1);
}
fscanf(fin, "%d %d", &N, &P);
result = exp_log_rec(N, P);
fprintf(fout, "%d\n", result);
fclose(fin);
fclose(fout);
return 0;
}