Skip to content

Commit

Permalink
Merge pull request #104 from vitorsantanna2/challenges/4-emprestimo/c…
Browse files Browse the repository at this point in the history
…/vitorsantanna2

Finalizando o desafio
  • Loading branch information
lanjoni authored Oct 5, 2023
2 parents f899e4b + 8454d4a commit 54da11e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions challenges/4-emprestimo/c/vitorsantanna2/README.md
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"
```
33 changes: 33 additions & 0 deletions challenges/4-emprestimo/c/vitorsantanna2/main.c
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;
}

0 comments on commit 54da11e

Please sign in to comment.