Created
October 8, 2012 13:22
-
-
Save poying/3852512 to your computer and use it in GitHub Desktop.
ch4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main(void){ | |
int c, i, s, f = 1; | |
scanf("%d", &c); | |
while(c--){ | |
printf("%d: \n> ", c); | |
scanf("%d", &i); | |
if(f){ | |
f *= 0; | |
s = i; | |
}else if(s > i){ | |
s = i; | |
} | |
} | |
printf("ans:%d\n", s); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
double pow(double a, int b){ | |
double ans = 1.0; | |
while(b--){ | |
ans *= a; | |
} | |
return ans; | |
} | |
void count(double rate){ | |
double amo, pri = 1000.0; | |
int year; | |
printf("%4s%21s\n", "Year", "Amount on deposit"); | |
for(year = 1; year <= 10; year++){ | |
amo = pri * pow(1.0 + rate, year); | |
printf("%4d%21.2f\n", year, amo); | |
} | |
printf("===========================\n"); | |
} | |
void main(void){ | |
double i; | |
for(i=0.05; i<=0.10; i+=0.01){ | |
count(i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void main(void){ | |
int id, num; | |
double ans = 0; | |
scanf("%d %d", &id, &num); | |
switch(id){ | |
case 1: | |
ans = 2.89; | |
break; | |
case 2: | |
ans = 4.50; | |
break; | |
case 3: | |
ans = 9.98; | |
break; | |
case 4: | |
ans = 4.49; | |
break; | |
case 5: | |
ans = 6.87; | |
break; | |
} | |
ans *= num; | |
printf("%f\n", ans); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void convert(char *ans, int num, int n){ | |
int counter = 0, len; | |
while(num){ | |
len = strlen(ans); | |
while(len--){ | |
ans[len+1] = ans[len]; | |
} | |
ans[0] = num % n; | |
ans[0] = ans[0] >= 10? ans[0] + 55: ans[0] + 48; | |
ans[counter+1] = 0; | |
num /= n; | |
counter++; | |
} | |
} | |
void main(void){ | |
char ans[80]; | |
int a[3] = {2, 12, 10}, | |
counter, | |
i; | |
counter = 3; | |
while(counter--){ | |
printf("%d\t", a[counter]); | |
} | |
printf("\n========================\n"); | |
for(i = 128; i <= 192; i++){ | |
counter = 3; | |
while(counter--){ | |
convert(ans, i, a[counter]); | |
printf("%s\t", ans); | |
} | |
printf("\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int in(int *h, int s2, int size){ | |
while(size--){ | |
if(h[size] == s2){ | |
return 1; | |
} | |
} | |
return 0; | |
} | |
void main(void){ | |
int i = 100, s1, s2, size = 0; | |
while(i){ | |
int h[80] = {0}; | |
s1 = i - 1; | |
size = 0; | |
while(s1){ | |
s2 = i - 1; | |
while(s2){ | |
if(i * i == s1 * s1 + s2 * s2 && ! in(h, s2, size)){ | |
h[size] = s1; | |
size++; | |
printf("斜邊: %d \t%d\t%d\n", i, s1, s2); | |
break; | |
} | |
s2--; | |
} | |
s1--; | |
} | |
i--; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int CountMonthDays(int y, int m){ | |
int big[6] = {1, 3, 5, 7, 8, 11}, | |
i = 6; | |
if(m == 2){ | |
return y % 4 == 0? 29: 28; | |
} | |
while(i--){ | |
if(big[i] == m){ | |
return 31; | |
} | |
} | |
return 30; | |
} | |
void main(void){ | |
int days, y, m, i, fd; | |
char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | |
while(1){ | |
printf("輸入年:\n> "); | |
scanf("%d", &y); | |
printf("輸入月:\n> "); | |
scanf("%d", &m); | |
printf("輸入第一日:\n> "); | |
scanf("%d", &fd); | |
printf("\n"); | |
i = 7; | |
while(i--){ | |
printf("%s \t", *(week + 6 - i)); | |
} | |
printf("\n"); | |
i = fd; | |
while(i--){ | |
printf("\t"); | |
} | |
days = CountMonthDays(y, m); | |
i = days; | |
while(i--){ | |
printf("%d\t", days - i); | |
if(fd == 6){ | |
fd = 0; | |
printf("\n"); | |
continue; | |
} | |
fd++; | |
} | |
printf("\n\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int CountMonthDays(int y, int m){ | |
int big[7] = {1, 3, 5, 7, 8, 10, 12}, | |
i = 7; | |
if(m == 2){ | |
return y % 4 == 0? 29: 28; | |
} | |
while(i--){ | |
if(big[i] == m){ | |
return 31; | |
} | |
} | |
return 30; | |
} | |
int CountLeapDays(int y, int m, int d){ | |
int ans, t1; | |
t1 = y - 2000; | |
ans = t1 / 4 + 1; | |
t1 %= 4; | |
if(! t1 && m <= 2 && d < 29){ | |
ans -= 1; | |
} | |
return ans; | |
} | |
int main(void){ | |
int i, j, y, t1, t2, | |
M[12] = {5, 1, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3}; | |
char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; | |
printf("輸入年:\n> "); | |
scanf("%d", &y); | |
i = 12; | |
while(i--){ | |
printf("\n\n%d月\n", 12 - i); | |
j = 7; | |
while(j--){ | |
printf("%s \t", *(week + 6 - j)); | |
} | |
printf("\n"); | |
t1 = (y - 2000 + CountLeapDays(y, 11 - i, 1) + M[11 - i] + 1) % 7; | |
j = t1; | |
while(j--){ | |
printf("\t"); | |
} | |
t2 = CountMonthDays(y, 12 - i); | |
j = t2; | |
while(j--){ | |
printf("%d\t", t2 - j); | |
if(t1 == 6){ | |
printf("\n"); | |
t1 = 0; | |
continue; | |
} | |
t1++; | |
} | |
printf("\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment