-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from vitorsantanna2/challenges/4-emprestimo/c…
…/vitorsantanna2 Finalizando o desafio
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Submissão de Exercicio | ||
|
||
**Exercicio:** 4 - Empréstimo | ||
|
||
**Nickname:** vitorsantanna2 | ||
|
||
**Nível Técnico:** - Estudante | ||
|
||
**Universidade:** - 42 Rio | ||
|
||
**Twitter**: https://twitter.com/BrazilwithHK | ||
|
||
**Dificuldade de Resolução:** - Média | ||
|
||
**Comentários:** Esse desafio envolve uma dificuldade maior por conta do parsing das inputs, mas no entanto, a lógica do empréstimo é simples. | ||
|
||
**Como rodar o desafio**: | ||
|
||
Use o comando abaixo: | ||
```bash | ||
cc main.c && ./a.out argv1,argv2,argv3 | ||
|
||
ou | ||
|
||
cc main.c && ./a.out "argv1, argv2, argv3" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
double power(double x, double y) | ||
{ | ||
double res; | ||
|
||
res = 1; | ||
while (y > 0) | ||
{ | ||
res *= x; | ||
y--; | ||
} | ||
return res; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
float value; | ||
int juros; | ||
int years; | ||
float res; | ||
|
||
if (argc != 2) | ||
return 1; | ||
value = atof(strtok(argv[1], ", ")); | ||
juros = atoi(strtok(NULL, ", ")); | ||
years = atoi(strtok(NULL, ", ")); | ||
res = value * power((1 + juros / 100.0), years); | ||
printf("%.2f\n", res); | ||
return 0; | ||
} |