Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
interestCalculationSample
#include <stdio.h> #define NUM_RATES (sizeof(value)/sizeof(value[0])) /* NUM_RATES is a macro that finds the length of the array based on the SIZE OF THE ARRAY in bytes ( size of(value) ) DIVIDED BY the SIZE OF EACH ELEMENT ( sizeof(value[0]) ) */ #define INITIAL_BALANCE 100.00 main(){ int low_rate; /*User input --- the lowest interest rate*/ int num_years; /*User input --- the number of years*/ int i; int year; float value[5]; /*Remember that the number in the brackets represents the number of elements --- 1 for each of the 5 year timeline in this case */ printf("Enter interest rate: "); scanf("%d", &low_rate); printf("Enter number of years: "); scanf("%d", &num_years); printf("\nYears"); /*This statement prints out the label for the "YEAR" column on the left side of the chart */ /*This loop prints out the LABELS FOR THE INTEREST RATE ROW AT THE TOP. Right next to the "Year" */ for (i = 0; i < NUM_RATES; i++) { /* NUM_RATES is 5 here Remember that NUM_RATES, seen above, is a macro for (sizeof(value)/sizeof(value[0])) This macro measures the LENGTH of the array by dividing the array size in bytes by the element size in bytes The macro format makes it easy for the loops to adjust if we need to CHANGE THE SIZE OF THE ARRAY */ printf("%6d", low_rate + i); /* Prints out the low rate + i according to the loop above */ value[i] = INITIAL_BALANCE; // set each value to the initial value } printf("\n"); /* This statement starts a new line for the loop below */ /* This loop prints the numbers IN THE YEARS COLUMN. Counts from 1 to the number of years entered by the user */ for (year = 1; year <= num_years; year++) { printf("%3d ", year); /* This NESTED loop increments the interest rate FROM ITS LOWEST VALUE TO ITS HIGHEST VALUE AND MULTIPLIES IT BY $100. Occurs right after the year column entry printed */ for (i = 0 ; i < NUM_RATES ; i++) { printf("value[%d] before applying interest: %7.2f\n",i,value[i]); value[i] = value[i] + ( ((low_rate + i) / 100.0) * value[i]); printf("value after applying interest %7.2f\n", value[i]); } printf("\n"); /*This statement causes the value to be placed on the next line*/ } return 0; }
run
|
edit
|
history
|
help
0
Eukleidova algoritmu
fun kce
Graph Depth First Search
UDP - Pytagorova veta
CV09-2
myblkqsort-ptr 20m numbers
Lazy dope vectors by Henry Kroll III www.thenerdshow.com
lab7_OOP 0.3
Run code before/after main in C (Clang)
life