Last active
August 29, 2015 14:20
-
-
Save unvBell/698f4e6c24f5e4ba1ef0 to your computer and use it in GitHub Desktop.
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
// 数値の四則演算結果を出力せよ | |
// in:A B | |
#include <stdio.h> | |
int main(void) { | |
double a, b; | |
puts ("?"); | |
scanf("%lf%lf", &a, &b); | |
printf("a+b=%f\n", a+b); | |
printf("a-b=%f\n", a-b); | |
printf("a*b=%f\n", a*b); | |
b == 0. ? puts("0div!") : printf("a/b=%f\n", a/b); | |
return 0; | |
} |
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
// 入力された2015年度の月日から2015年3月31日までの日数を求めよ | |
// in:M D | |
#include <stdio.h> | |
int main(void) { | |
int month, day, daysLeft, i; | |
// 4月始まりの日数テーブル | |
const int daysTable[12] = { | |
30, 31, 30, 31, 31, 30, | |
31, 30, 31, 31, 28, 31, | |
}; | |
puts ("?"); | |
scanf("%d%d", &month, &day); | |
// 1月始まりから4月始まりの月番号に変換 | |
// 4 -> 0 | |
// 2 -> 10 | |
month = ((month-4) + 12)%12; | |
daysLeft = -day; | |
for(i=month; i<12; i++) { | |
daysLeft += daysTable[i]; | |
} | |
printf("days left %d", daysLeft); | |
return 0; | |
} |
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
// 入力された整数の金種表を出力せよ | |
// in:N | |
#include <stdlib.h> | |
#include <stdio.h> | |
struct Money { | |
int value; | |
const char* name; | |
}; | |
int main(void) { | |
int value; | |
const struct Money* money; | |
const struct Money moneyList[] = { | |
{ 10000, "壱万円札" }, | |
{ 5000, "五千円札" }, | |
{ 2000, "弐千円札" }, | |
{ 1000, "千円札" }, | |
{ 500, "五百円玉" }, | |
{ 100, "百円玉" }, | |
{ 50, "五十円玉" }, | |
{ 10, "十円玉" }, | |
{ 5, "五円玉" }, | |
{ 1, "一円玉" }, | |
{ 0, NULL }, | |
}; | |
puts ("?"); | |
scanf("%d", &value); | |
for(money=moneyList; money->value; money++) { | |
div_t d; | |
d = div(value, money->value); | |
value = d.rem; | |
printf("%s\t|%4d枚\n", money->name, d.quot); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment