#include <stdio.h> #define MOVE 1 #define END 10 #define GOUPOS 6 #define GOU 2 void ObayGou(int *n) { printf("Obay Gou!\n"); *n += GOU; } int IsInGou(int n) { if ( n == GOUPOS ) return 1; else return 0; } int main(int argv, char **argc) { int You = 0; while ( You < END ){ if ( IsInGou(You) ){ ObayGou(&You); } else{ printf(",,,n\n"); You += MOVE; } } }
/* 郷にいれば郷に従え.c */ #include <stdio.h> enum {NO=0, GOU=1}; static int Position[]={NO,NO,NO,NO,GOU}; int obey(int n, int pos) { printf("Obey Gou.\n"); } void main(int ac, char **av) { int you; for(you=0; ; you++) { if (Position[you]==GOU) { obey(you,Position[you]); break; } else { printf("...\n"); } } } /* 郷にいれば郷に従え.c その2 */ #include <stdio.h> int gou() { printf("Obey Gou.\n"); return 1; } int ignore() { printf(".........\n"); return 0; } static int (*Obey[])()={ignore,ignore,ignore,ignore,gou}; void main(int ac, char **av) { int you; for(you=0; !(*Obey[you])(); you++) ; }
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(int argv, char **argc) { srand((int)time(0)); printf("%d\n",rand()%6); }
/* rome.c */ #include<stdio.h> #define ONEDAY (60*60*24+1) main() { long Rome; long sec; for (Rome=0; Rome<=ONEDAY; Rome++) { for(sec=time(0); sec==time(0);) ; printf("Now Constructing Rome %f %%\n",Rome*100.0/ONEDAY); } printf("Complete!\n"); }
/* 鳴かぬなら鳴くまでまとうほととぎす.c */ #include <stdio.h> void main() { while(!isCry("HOTOTOGISU")) ; }