English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

以下是我的程式 看看怎樣寫才能寫出輸入n個值比大小
上面的還有 總和 還有公式之累的 請專注於 for迴圈內所用的n值比大小 ,請幫我改成 兩種編寫法 1>用陣列來比大小2>布用陣列的方法


int main()
{
double average,sum_squares,standard_deviation;
int num;
printf("how many numbers you want to compute?");scanf("%d",&num);
int i,sum=0,temp,min=0,max=0,j,n=0,m=0,k;

for(i=0;i {
printf("NO.%d\n",i+1);
scanf("%d",&temp);
sum += temp;
max=temp;
min=temp;
if (temp>max)
max=temp;
else if(temp min=temp;

}
average=sum/num;
standard_deviation=sqrt(sum/num-average*average);
printf("標準誤差值為%lf",standard_deviation);
printf("最小值為%d",min);
printf("最大值為%d",max);
system("pause");
return(0);
}

2007-11-18 16:41:59 · 1 個解答 · 發問者 一航 1 in 電腦與網際網路 程式設計

1 個解答

#include
#include
void sort(int Length, int *Number){
int l=Length,*n=Number,tmp,i,j;
for(i=0;i for(j=i;j if(n[i]>n[j])
tmp=n[i],n[i]=n[j],n[j]=tmp;
}
int main(int argc, char* argv[]){
//=====START=====//
int n,*p,i;
printf("Input the number of numbers: "),scanf("%d",&n);
p=(int*)malloc(sizeof(int)*n);
for(i=0;i printf("no.%d: ",i+1),scanf("%d",(p+i));
}
sort(n,p);
for(i=0;i printf("p[%d]= %d\n",i,p[i]);
}
free(p);
//=====END=====//
system("PAUSE");
return 0;
}

2007-11-19 13:56:32 · answer #1 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers