Thursday, January 28, 2016

Calculate The Depreciation with C

For my improvement, I follow the book that guide me into a topic of depreciation. The definition of depreciation itself: method of calculating the cost of tangible assets over it useful life.

For example, if a business purchases a delivery truch with a cost of Rp. 150.000.000 and it is expected to be used for 5 years. The business might have depreciation expense of expected years with the calculation :

first we sum of 5 years  :
 sum = 1+2+3+4+5=15 -->  15 can be formulated as 
 sum = n(n+1)/2
 n is for calculated years

The depreciation of every years can be like this:
  • depreciation of 1 years: 5/15*Rp. 150.000.000 =  Rp. 50.000.000
  • depreciation of 1 years: 4/15*Rp. 150.000.000 =  Rp. 40.000.000
  • depreciation of 1 years: 3/15*Rp. 150.000.000 =  Rp. 30.000.000
  • depreciation of 1 years: 2/15*Rp. 150.000.000 =  Rp. 20.000.000
  • depreciation of 1 years: 1/15*Rp. 150.000.000 =  Rp. 10.000.000

In this learn, We will make a code how to  make a list of depreciation as above 

Here is the code I adopted from C handbook:
     ------------------------------------------------------------

#include<stdio.h>

main ()

{
long int cost;
int i, sum, year;
double deprec;
printf("Cost: ");
scanf("%d", &cost);
printf("Year: ");
scanf("%d", &year);
sum = year * (year+1)/2;
for (i=1;i<=year;i++)
{
deprec = (year + 1.0 - i)/sum*cost;
printf("%2d %.0lf\n", i, deprec);
}
return 0;
}

-------------------------------------------------
The outcome:

No comments: