[ create a new paste ] login | about

Link: http://codepad.org/XnGsYKmG    [ raw code | output | fork ]

C, pasted on Jun 28:
#include<stdio.h>
typedef struct
{
  char name[32];
  double height;
}Student;

int main(void)
{
  Student p[5];
  int i;
  for(i=0;i<=4;i++)
    {
      printf("%d番目の名前は?:",i+1);
      scanf("%s",p[i].name); // scanf("%s",p.name);
      printf("身長は?:");
      scanf("%lf",&p[i].height); // scanf("%lf",&p.height);
    }

  int j;
  Student tmp;
  for ( i=0; i<=4; ++i )
    for ( j=4; j>i; --j )
      {
        if ( p[j-1].height > p[j].height ) {
          tmp = p[j];
          p[j] = p[j-1];
          p[j-1] = tmp;
        }
      }

  printf( "--------------------\n" );
  const char* kans[] = { "一", "二", "三", "四", "五" };
  for ( i=0; i<=4; ++i )
    printf( "%s人目:名前 %s   身長 %lf\n", kans[i], p[i].name, p[i].height );

  return 0;
}


Output:
1
2
3
4
5
6
1番目の名前は?:身長は?:2番目の名前は?:身長は?:3番目の名前は?:身長は?:4番目の名前は?:身長は?:5番目の名前は?:身長は?:--------------------
一人目:名前 tP@   身長 -0.002362
二人目:名前    身長 0.000000
三人目:名前 0Xc�'�   身長 2.228371
四人目:名前 �Xc�T�@4I@$�@   身長 2.374477
五人目:名前 ́�Xc�xY@   身長 5.201203


Create a new paste based on this one


Comments: