Cod sursa(job #3134789)
| Utilizator | Data | 30 mai 2023 22:36:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
//
// main.c
// ridicare_putere_log
//
// Created by Bran Eduard Denis on 30.05.2023.
//
#include <stdio.h>
#include <stdlib.h>
float putere(float x, int n)
{
if(n<0)
return putere(1.0/x,(-1)*n);
if(n==0)
return 1;
if(n%2==0)
return putere(x*x,n/2);
else
return putere(x*x,n/2)*x;
}
int main() {
int N,P;
FILE*f;
f=fopen("lgput.in","rt");
fscanf(f,"%d %d",&N,&P);
f=fopen("lgput.out","wt");
fprintf(f,"%d",putere(N,P));
fclose(f);
return 0;
}
