Would you like to react to this message? Create an account in a few clicks or log in to continue.


您沒有登錄。 請登錄註冊

【C語言】計算平均值

2 posters

向下  內容 [第1頁(共1頁)]

1【C語言】計算平均值 Empty 【C語言】計算平均值 周日 2月 27, 2011 10:04 pm

Williamd

Williamd
Admin

代碼:
/*輸入正整數N得到總項數,依序輸入1~N各項數值求出平均值*/

#include <stdio.h>

void main()
{
   float s=0; /*宣告浮點數S初始值等於0*/
   int n , m; /*宣告正整數n(項數),m(遞回次數))*/
   
   printf("總項數 = ");
   scanf("%d",&n);
   float x[n]; /*宣告浮點數陣列x[n],n等於維數*/
   
   for(m = 0; m < n ; m++){
      printf("請輸入第%d項之值 : ",m+1);
      scanf("%f",&x[m]); /*輸入一個值到x陣列裡的第m維*/
      s = s + x[m];
      }
   
   printf("總平均 : %f", s / n);   
      
 
  system("PAUSE");   
  return 0;
}

http://c-wind.luntanlong.com

2【C語言】計算平均值 Empty 回復: 【C語言】計算平均值 周一 2月 28, 2011 7:01 pm

Wildsky

Wildsky
C-Wind 特級資訊院士

沒辦法= =


void main()
{                   
float s=0; /*宣告浮點數S初始值等於0*/




紅色部分出錯

http://www.wretch.cc/blog/kevinboy3110

回頂端  內容 [第1頁(共1頁)]

這個論壇的權限:
無法 在這個版面回復文章