연간 감가상각표 출력
이 단계에서는 자산의 경제적 수명 동안 연간 감가상각액과 장부가치를 보여주는 자세한 감가상각표를 출력하는 감가상각 프로그램을 개선합니다.
depreciation.c 파일을 수정하여 포괄적인 감가상각표를 포함합니다.
cd ~/project
nano depreciation.c
연간 감가상각표를 출력하도록 코드를 업데이트합니다.
#include <stdio.h>
int main() {
float cost, salvage_value, useful_life, annual_depreciation;
float book_value;
int year;
// 사용자에게 자산 원가를 입력하도록 요청
printf("Enter the asset cost: ");
scanf("%f", &cost);
// 사용자에게 잔존 가치를 입력하도록 요청
printf("Enter the salvage value: ");
scanf("%f", &salvage_value);
// 사용자에게 경제적 수명 (년 단위) 을 입력하도록 요청
printf("Enter the useful life (in years): ");
scanf("%f", &useful_life);
// 연간 감가상각액 계산
annual_depreciation = (cost - salvage_value) / useful_life;
// 감가상각표 헤더 출력
printf("\n감가상각표:\n");
printf("---------------------------------------------\n");
printf("년도\t시작 가치\t감가상각액\t종료 가치\n");
printf("---------------------------------------------\n");
// 장부가치 초기화
book_value = cost;
// 각 년도의 감가상각 출력
for (year = 1; year <= useful_life; year++) {
printf("%d\t$%.2f\t\t$%.2f\t\t$%.2f\n",
year,
book_value,
annual_depreciation,
book_value - annual_depreciation);
// 장부가치 업데이트
book_value -= annual_depreciation;
}
return 0;
}
업데이트된 프로그램을 컴파일하고 실행합니다.
gcc depreciation.c -o depreciation
./depreciation
예시 출력:
Enter the asset cost: 50000
Enter the salvage value: 5000
Enter the useful life (in years): 5
감가상각표:
---------------------------------------------
년도 시작 가치 감가상각액 종료 가치
---------------------------------------------
1 $50000.00 $9000.00 $41000.00
2 $41000.00 $9000.00 $32000.00
3 $32000.00 $9000.00 $23000.00
4 $23000.00 $9000.00 $14000.00
5 $14000.00 $9000.00 $5000.00