$B1i=,$N2rEz(B

$BBh0l2s(B

$B1i=,(B 1-1

Hello World $B$HI=<($5$l$k(B

$B1i=,(B 1-2

  1. 
    #include <stdio.h>
    #define N 5
    main(){
      int i,j;
      for(i=0;i<N;i++){
        for(j=0;j<N-i;j++){
          printf("$B!{(B");
        }
        printf("\n");
      }
    }
    
  2. 
    #include <stdio.h>
    #define N 4
    main(){
      int i,j;
      for(i=0;i<N;i++){
        for(j=0;j<N-i-1;j++){
          printf("$B!!(B");
        }
        for(j=0;j<2*i+1;j++){
          printf("$B!{(B");
        }
        printf("\n");
      }
    }
    
  3. 
    #include <stdio.h>
    #define N 3
    main(){
      int i,j;
      for(j=0;j<N+2;j++){
        printf("$B!{(B");
      }
      printf("\n");
      for(i=0;i<N;i++){
        printf("$B!{(B");
        for(j=0;j<N;j++){
          printf("$B!!(B");
        }
        printf("$B!{(B\n");
      }
      for(j=0;j<N+2;j++){
        printf("$B!{(B");
      }
    }
    

$BBhFs2s(B

$B1i=,(B 2-1

  1. 
    #include <stdio.h>
    main(){
      int a[]={5, 2, 6, 3, 1, -1};
      int i,k;
      k=0;
      for(i=0;a[i]!=-1;i++){
        k++;
      }
      printf("%d\n",k);
    }
    
  2. 
    #include <stdio.h>
    main(){
      int a[]={5, 2, 6, 3, 1, -1};
      int i,goukei;
      goukei=0;
      for(i=0;a[i]!=-1;i++){
        goukei+=a[i];
      }
      printf("%d\n",goukei);
    }
    
  3. 
    #include <stdio.h>
    main(){
      int a[]={5, 2, 6, 3, 1, -1};
      int i,k,goukei;
      k=0;
      goukei=0;
      for(i=0;a[i]!=-1;i++){
        k++;
        goukei+=a[i];
      }
      printf("%f\n",(float)goukei/k);
    }
    

$BBh;02s(B

$B1i=,(B 3-1

  1. 
    #include <stdio.h>
    main(){
      char x[]="abc";
      int i,k;
      k=0;
      for(i=0;x[i]!='\0';i++){
        k++;
      }
      printf("%d\n",k);
    }
    
  2. 
    #include <stdio.h>
    main(){
      char x[]="This is a pin.";
      int i,k;
      k=0;
      for(i=0;x[i]!='\0';i++){
        if(a[i]=='i'){
          k++;
        }
      }
      printf("%d\n",k);
    }
    
  3. 
    #include <stdio.h>
    main(){
      char x[]="This is a pin.";
      int i;
      char c;
      for(i=0;x[i]!='\0';i++){
        c=x[i];
        if((c>='a')&&(c<='z')){
          c=c-'a'+'A';
        }
        printf("%c",c);
      }
    }
    
  4. 
    #include <stdio.h>
    main(){
      char x[]="abc";
      char y[]="def";
      char z[50];
      int i,j;
      for(i=0;x[i]!='\0';i++){
        z[i]=x[i];
      }
      for(j=0;y[j]!='\0';j++){
        z[i]=y[j];
        i++;
      }
      z[i]='\0';
      printf("$BJ8;zNs(B %s $B$H(B %s $B$r$D$J$2$k$H(B %s $B$K$J$k(B\n",x,y,z);
    }
    

$BBh;M2s(B

    1. i=2, j=1
    2. i=1. j=0
    3. i=0
  1. #include <stdio.h>
    #define N 3
    main(){
      FILE* fh;
      int i,j;
      if((fh=fopen("zukai.txt","w"))==NULL){
        fprintf(stderr,"$B%U%!%$%k$r3+$1$^$;$s$G$7$?(B\n");
        exit(1);
      }
      for(i=0;i<N;i++){
        for(j=0;j<N-i-1;j++){
          fprintf(fh,"  ");
        }
        fprintf(fh,"$B!{(B");
        if(i>0){
          for(j=0;j<2*i-1;j++){
    	fprintf(fh,"  ");
          }
          fprintf(fh,"$B!{(B");
        }
        fprintf(fh,"\n");
      }
      for(i=N-2;i>=0;i--){
        for(j=0;j<N-i-1;j++){
          fprintf(fh,"  ");
        }
        fprintf(fh,"$B!{(B");
        if(i>0){
          for(j=0;j<2*i-1;j++){
    	fprintf(fh,"  ");
          }
          fprintf(fh,"$B!{(B");
        }
        fprintf(fh,"\n");
      }
      fclose(fh);
    }
    
  2. #include <stdio.h>
    main(){
      FILE *fh;
      char filename[]="4-3.c";
      char c;
      int n=0;
      if((fh=fopen(filename,"r"))!=NULL){
        while((c=getc(fh))!=EOF){
          n++;
        }
        printf("$B9g7W(B %d $BJ8;z(B\n",n);
        fclose(fh);
      }else{
        fprintf(stderr,"$B%U%!%$%k(B %s $B$r3+$1$^$;$s$G$7$?(B\n",filename);
      }
    }
    
  3. #include <stdio.h>
    main(){
      FILE *fh;
      char filename[]="4-4.c";
      char c;
      char x='a';
      int n=0;
      if((fh=fopen(filename,"r"))!=NULL){
        while((c=getc(fh))!=EOF){
          if(c==x){
            n++;
          }
        }
        printf("%c $B$O9g7W(B %d $BJ8;z(B\n",x,n);
        fclose(fh);
      }else{
        fprintf(stderr,"$B%U%!%$%k(B %s $B$r3+$1$^$;$s$G$7$?(B\n",filename);
      }
    }
    
  4. #include <stdio.h>
    main(){
      FILE *fh;
      char filename[]="4-5.c";
      char c;
      int n=0;
      if((fh=fopen(filename,"r"))!=NULL){
        while((c=getc(fh))!=EOF){
          if(c=='\n'){
            n++;
          }
        }
        printf("$B9g7W(B %d $B9T(B\n",n);
        fclose(fh);
      }else{
        fprintf(stderr,"$B%U%!%$%k(B %s $B$r3+$1$^$;$s$G$7$?(B\n",filename);
      }
    }
    
  5. #include <stdio.h>
    main(){
      FILE *fh;
      char filename[]="4-6.c";
      char c;
      int n=0;
      if((fh=fopen(filename,"r"))!=NULL){
        while((c=getc(fh))!=EOF){
          n++;    
          if(c=='\n'){
            printf("%d $BJ8;z(B\n",n);
            n=0;
          }
        }
        if(n!=0){
          printf("%d $BJ8;z(B\n",n);
        }
        fclose(fh);
      }else{
        fprintf(stderr,"$B%U%!%$%k(B %s $B$r3+$1$^$;$s$G$7$?(B\n",filename);
      }
    }
    
  6. #include <stdio.h>
    main(){
      char c;
      int n=0;
      while((c=getchar())!=EOF){
        if(c=='\n'){
          printf("\n");
          n=0;
        }else{
          if(n>=10){
            printf("\n");
            n=0;
          }
          printf("%c",c);
          n++;
        }      
      }      
    }
    

$BBh8^2s(B

$B1i=,(B 5-5


#include <stdio.h>
main(){
  char x[]="abcdef";
  char y[50];
  char *p,*q;
  p=x;
  q=y;
  while((*q++=*p++)!='\0');
  printf("%s $B$r%3%T!<$7$?7k2L(B %s $B$H$J$k(B\n",x,y);
}

$B1i=,(B 5-6


#include <stdio.h>
void copy(char *a, char *b){
  while((*b++=*a++)!='\0');
}
main(){
  char x[]="abcdef";
  char y[50];
  copy(x,y);
  printf("%s $B$r%3%T!<$7$?7k2L(B %s $B$H$J$k(B\n",x,y);
}

$BBhO;2s(B

$B1i=,(B 6-1


#include <stdio.h>
#include <math.h>
typedef struct point {
  double x;
  double y;
} POINT;
double distance(POINT p){
  return sqrt(p.x*p.x+p.y*p.y);
}
main(){
  POINT p={3.0,4.0};
  printf("$BE@(B %f, %f $B$H86E@$N5wN%$O(B %f $B$G$9!#(B\n",p.x,p.y,distance(p));
}

$B1i=,(B 6-2


#include <stdio.h>
typedef struct point {
  double x;
  double y;
} POINT;
void half(POINT *p){
  p->x/=2;
  p->y/=2;
}
main(){
  POINT p={6.0,8.0};
  printf("$B:G=i$NE@$O(B %f, %f $B$G$9!#(B\n",p.x,p.y);
  half(&p);
  printf("$BH>J,$N0LCV$O(B %f, %f $B$G$9!#(B\n",p.x,p.y);
}

$BBh<72s(B

$B1i=,(B 7-1

5!=120, 6!=720

$B1i=,(B 7-2

  1. 
    #include <stdio.h>
    int fibo(int n){
      if(n==0){ return 1; }
      if(n==1){ return 1; }
      return fibo(n-1)+fibo(n-2);
    }
    main(){
      printf("%d\n",fibo(20));
    }
    

    10946

  2. 
    #include <stdio.h>
    #define N 100
    int a[N];
    int fibo(int n){
      if(a[n]>0){ return a[n];}
      if(n==0){ return 1; }
      if(n==1){ return 1; }
      a[n]=fibo(n-1)+fibo(n-2);
      return a[n];
    }
    main(){
      int i;
      for(i=0;i<N;i++){a[i]=0;}
      printf("%d\n",fibo(45));
    }
    

    a40=165580141

    $BC"$7!"1i=,<<$N4D6-$@$H4JC1$K5a$^$C$F$7$^$C$?$?$a!"(B a45$B$NCM(B 1836311903 $B$b5a$a$?!#(B

$B1i=,(B 7-3


#include <stdio.h>
int combi(int n, int m){
  if(m==0){ return 1; }
  if(m==n){ return 1; }
  return combi(n-1,m-1)+combi(n-1,m);
}
main(){
  printf("%d, %d\n",combi(5,2),combi(20,2));
}

10, 190 $B$,I=<($5$l$k(B

$B1i=,(B 7-4

hanoi(3,'a','b','c')
move 1 from a to b
move 2 from a to c
move 1 from b to c
move 3 from a to b
move 1 from c to a
move 2 from c to b
move 1 from a to b
hanoi(4,'a','b','c')
move 1 from a to c
move 2 from a to b
move 1 from c to b
move 3 from a to c
move 1 from b to a
move 2 from b to c
move 1 from a to c
move 4 from a to b
move 1 from c to b
move 2 from c to a
move 1 from b to a
move 3 from c to b
move 1 from a to c
move 2 from a to b
move 1 from c to b

$BBhH,2s(B

$B1i=,(B 8-1

$B?^$O>JN,!#(B 14$B

$B1i=,(B 8-2

0110
1010
1101
0010

$B1i=,(B 8-3


#include 
#define MAX 10
main(){
  int i,j,degree,kiten;
  int a[MAX][MAX];
  printf("$BD:E@?t$rF~$l$F2<$5$$!#(B\n");
  scanf("%d",&n);
  kiten=0;
  for(i=0;i<n;i++){
    degree=0;    
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j];);
      degree+=a[i][j];
    }
    kiten+=degree%2
  }
  if((kiten==0)||(kiten==2)){
    printf("$B0lI.=q$-$G$-$^$9!#(B\n");
  }else{
    printf("$B0lI.=q$-$G$-$^$;$s!#(B\n");
  }
}

$BBh6e2s(B

$B1i=,(B 9-1


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 80
char buffer[SIZE+1];
typedef struct lst {
  char *item;
  struct lst *next;
} LIST;
LIST* newnode(){
   LIST *p;
   p=(LIST *)malloc(sizeof(LIST));
   p->next=NULL;
   return p;
}
void add(LIST *p,char *c){
  if(p->next == NULL){
    p->item=c;
    p->next=newnode();
  }else{
    add(p->next,c);
  }
}  
void reverseshow(LIST *p){
  if(p->next != NULL){
    reverseshow(p->next);
    printf("%s\n",p->item);
  }
}
main(){
  char c;
  int i=0;
  char filename[]="input.txt";
  FILE *fh;
  LIST *l;
  l=newnode();
  if((fh=fopen(filename,"r"))!=NULL){
    while((c=getc(fh))!=EOF){
      if(c!='\n'){
	if(i<SIZE){
	  buffer[i++]=c;
	}
      }else{
	buffer[i]='\0';
	add(l,strdup(buffer));
	i=0;
      }
    }
    reverseshow(l);
    fclose(fh);
  }else{
    fprintf(stderr,"$B%U%!%$%k(B %s $B$,$"$j$^$;$s!#(B\n",filename);
  }
}

$B1i=,(B 9-2

$B:[email protected](B

$BBh==2s(B

$B1i=,(B 10-1

$B

def
ghi
abc

$B1i=,(B 10-2

$BNc(B 2 $B$H=EJ#(B

$B1i=,(B 10-3

$B:[email protected](B


$B:dK\D>;V(B <[email protected]>
$BEl5~EE5!Bg3X9)3XIt>pJsDL?.9)3X2J(B