장용운 C과제 HW1
Write a program that reads a four digit integer and prints the sum of its digits as an output. ¶
////////////////////////////// // C Programming Homework 1 // ////////////////////////////// // // // Problem Number : 1 // // // // Student ID : 20114924 // // // // Student Name : 장용운 // // // ////////////////////////////// #include <stdio.h> #define fdn four_digit_num int main(void) { int fdn; scanf("%d", &fdn); // printf("The sum of four numbers : %d\n", (fdn/1000%10) + (fdn/100%10) + (fdn/10%10) + (fdn%10)); printf("The sum of four numbers : %d\n", (int)(fdn/1000) + (fdn/100%10) + (fdn/10%10) + (fdn%10)); return 0; }
Write a C program that output as follows. ¶
<pre>
Output :
Output :
- **
- ****
- ******
</pre>
////////////////////////////// // C Programming Homework 1 // ////////////////////////////// // // // Problem Number : 2 // // // // Student ID : 20114924 // // // // Student Name : 장용운 // // // ////////////////////////////// #include <stdio.h> int main(void) { int i, j; for(i=0; i<5; i++) { for(j=4; j>i; j--) { printf(" "); } for(j=0; j<(i*2+1); j++) { printf("*"); } printf("\n"); } return 0; }
Write a program that gets a starting principal(A, 원금), annual interest rate(r, 연이율) from a keyboard (standard input) and print the total amount on deposit (예치기간이 지난 뒤 총금액, 원리합계) for the year(n) from 0 to 10. ¶
total deposit = A*(1+r)^n
For example,
1000.0 0.05 <- keyboard input // 5% should be written as 0.050 1000.00
1 1050.00
2 1102.50
3 1157.62
4 1215.51
5 1276.28
6 1340.10
7 1407.10
8 1477.46
9 1551.33
1 1050.00
2 1102.50
3 1157.62
4 1215.51
5 1276.28
6 1340.10
7 1407.10
8 1477.46
9 1551.33
10 1628.89
////////////////////////////// // C Programming Homework 1 // ////////////////////////////// // // // Problem Number : 3 // // // // Student ID : 20114924 // // // // Student Name : 장용운 // // // ////////////////////////////// #include <stdio.h> int main(void) { int i; float a, r; scanf("%f %f", &a, &r); r++; for(i=0; i<=10; i++) { printf("%5d %12.2f\n", i, a); a *= r; } return 0; }