[ create a new paste ] login | about

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

C, pasted on Jul 25:
#include<stdio.h> 
#include<stdlib.h> 

typedef int T; 

/***別に、int型をTと名前を付けなくてもいいでしょう。***/ 

void swap(T*a,T*b)
{ 
T temp; 
temp=*a; 
*a=*b; 
*b=temp; } 

void kansu(T*str,int n){ 
int i,j; 
int A; 

for(i=0;i<n-1;i++){ 
A=1; 
for(j=n-2;j>=i;--j) 
if(str[j]<str[j+1]){ 
swap(&str[j], &str[j+1]); 

/*** &x[i]は、x+i と表現できます。***/ 

A=0; 
} 

if(A) 
break; 
} 
} 
int main(void){ 
int n,i; 
T*str; 
printf("n="); 

if(scanf("%d",&n)!=1); 

/***このif文のふるまいが不明です。***/ 

if(n==0) 
printf("1以上の数字を入力して下さい。"); 
if((str=malloc(sizeof(T)*n))!=NULL){ 
i=0; 

/***適切なループ文に書き直してください。***/ 

while(i<n){ 
printf("データ%d=",i+1); 
if(scanf("%d",&str[i])==1) 

/*** ここも同様です。***/ 

i++; } 

kansu(str,n); 
for(i=0;i<n;i++) 
printf("%d,",str[i]); 
printf("\n"); 
free(str); 
} 

return(0); 
} 


Output:
1
n=


Create a new paste based on this one


Comments: