Good afternoon, I have a problem I need to do the following:
Create a program, in C language, that calculates the size of the tree of life, after a certain number of growth cycles, taking into account that the tree starts with one meter in size.
A tree, 1 meter in size, after 1 cycle, is 2 meters long.
A tree, 1 meter in length, after 2 cycles, is 3 meters long.
A tree, one meter in length, after 3 cycles, is 6 meters long.
A tree, 1 meter in length, after 4 cycles, is 7 meters long.
A tree, one meter in size, after 5 cycles, is 14 meters long.
A tree, one meter in size, after 6 cycles, is 15 meters.
A tree, 1 meter in length, after 7 cycles, is 30 meters long.
So far I've done the following
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void funcao_01() // sub programa
{
int ciclos;
printf(" \n\n -- ARVORE DA VIDA -- \n\n");// cabecalho
printf(" Digite o valor de ciclos desejados: ");
scanf("%d",&ciclos); // le valor digitado pelo usuario
float resultado;
if (ciclos % 2 == 1)
{
resultado = (ciclos * ciclos);
--resultado;
}
else
{
if(ciclos % 2 == 0)
{
resultado = ciclos * 2;
}
}
printf("\n\n Voce escolheu %d, ciclos\n\n Sendo assim voce tem %f metros.\n\n\n\n",ciclos, resultado);
}
int main() // programa principal
{
funcao_01(); // chama funcao
return 0;
}
because the relationship I had created was as follows:
"When the cycle is odd it doubles .. when it's even it adds +1"
At first, it worked, but when it starts with larger numbers, it does not have logic anymore, so I would like to "standardize" it, but my question is, what is the easiest method to solve this problem?