#include <stdio.h>
#include <string.h>
// Definição de constantes
#define TAXA_JUROS 0.05 // 5%
int main( ) {
// Variáveis primárias
float valor_inicial, valor_final;
int anos;
// Solicita ao usuário que insira o valor inicial do investimento e o número de anos
printf ( "Digite o valor inicial do investimento: " ) ; scanf ( "%f" , & valor_inicial
) ; printf ( "Digite o número de anos: " ) ;
// Calcula o valor final do investimento usando a fórmula de juros simples
valor_final = valor_inicial * ( 1 + ( TAXA_JUROS * anos) ) ;
// Exibe o valor final do investimento
printf ( "Valor final do investimento: %.2f\n " , valor_final
) ;
// Declara um vetor de inteiros com 3 elementos e inicializa
int vetor[ 3 ] = { 5 , 10 , 15 } ; // Valor de exemplo
// Declara uma matriz 2x2 de inteiros e inicializa
int matriz[ 2 ] [ 2 ] = { { 1 , 2 } , { 3 , 4 } } ; // Valor de exemplo
// Utiliza um ponteiro para acessar e modificar o primeiro elemento do vetor
int * ptr = vetor; // Ponteiro para o vetor
* ptr = 20 ; // Modifica o primeiro elemento do vetor para 20
// Exibição dos valores dos elementos do vetor e matriz
printf ( "Elementos do vetor:\n " ) ; for ( int i = 0 ; i < 3 ; i++ ) {
printf ( "vetor[%d] = %d, Endereço: %p\n " , i
, vetor
[ i
] , ( void * ) & vetor
[ i
] ) ; }
printf ( "\n Elementos da matriz:\n " ) ; for ( int i = 0 ; i < 2 ; i++ ) {
for ( int j = 0 ; j < 2 ; j++ ) {
printf ( "matriz[%d][%d] = %d, Endereço: %p\n " , i
, j
, matriz
[ i
] [ j
] , ( void * ) & matriz
[ i
] [ j
] ) ; }
}
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCi8vIERlZmluacOnw6NvIGRlIGNvbnN0YW50ZXMKI2RlZmluZSBUQVhBX0pVUk9TIDAuMDUgIC8vIDUlCgppbnQgbWFpbigpIHsKICAgIC8vIFZhcmnDoXZlaXMgcHJpbcOhcmlhcwogICAgZmxvYXQgdmFsb3JfaW5pY2lhbCwg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cm8gZWxlbWVudG8gZG8gdmV0b3IKICAgIGludCAqcHRyID0gdmV0b3I7ICAvLyBQb250ZWlybyBwYXJhIG8gdmV0b3IKICAgICpwdHIgPSAyMDsgIC8vIE1vZGlmaWNhIG8gcHJpbWVpcm8gZWxlbWVudG8gZG8gdmV0b3IgcGFyYSAyMAoKICAgIC8vIEV4aWJpw6fDo28gZG9zIHZhbG9yZXMgZG9zIGVsZW1lbnRvcyBkbyB2ZXRvciBlIG1hdHJpegogICAgcHJpbnRmKCJFbGVtZW50b3MgZG8gdmV0b3I6XG4iKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgMzsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCJ2ZXRvclslZF0gPSAlZCwgRW5kZXJlw6dvOiAlcFxuIiwgaSwgdmV0b3JbaV0sICh2b2lkKikmdmV0b3JbaV0pOwogICAgfQoKICAgIHByaW50ZigiXG5FbGVtZW50b3MgZGEgbWF0cml6OlxuIik7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDI7IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgMjsgaisrKSB7CiAgICAgICAgICAgIHByaW50ZigibWF0cml6WyVkXVslZF0gPSAlZCwgRW5kZXJlw6dvOiAlcFxuIiwgaSwgaiwgbWF0cml6W2ldW2pdLCAodm9pZCopJm1hdHJpeltpXVtqXSk7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiAwOwp9
stdout
Digite o valor inicial do investimento: Digite o número de anos: Valor final do investimento: 0.00
Elementos do vetor:
vetor[0] = 20, Endereço: 0x7ffde00d6e24
vetor[1] = 10, Endereço: 0x7ffde00d6e28
vetor[2] = 15, Endereço: 0x7ffde00d6e2c
Elementos da matriz:
matriz[0][0] = 1, Endereço: 0x7ffde00d6e30
matriz[0][1] = 2, Endereço: 0x7ffde00d6e34
matriz[1][0] = 3, Endereço: 0x7ffde00d6e38
matriz[1][1] = 4, Endereço: 0x7ffde00d6e3c