31 Aralık 2012 Pazartesi


輸入五個數字,分別計算出平均數、變異數、標準差,並精確到小數點後第二位。

平均數參考公式
μ=Σ(Xi)/N
變異數參考公式
Σ(Xi-μ)^2/N
標準差參考公式
(Σ(Xi-μ)^2/N)^(0.5)


例如:1 2 8 9 10
平均值:6.00  (1+2+8+9+10)/5=6
變異數:14.00 Σ(Xi-μ)^2=(1-6)^2+(2-6)^2+(8-6)^2+(9-6)^2+(10-6)^2
                        =25+16+4+9+16=70 70/5=14
標準差14^(0.5)

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <math.h>  
  4. int main(int argc, char *argv[])  
  5. {  
  6.   double a,b,c,d,e,ave,x,y;   
  7. //  pow(10,2);  
  8.   scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&d,&e);  
  9.     ave = (a + b + c + d + e)/5;  
  10.     x = ((pow((a-ave),2))+(pow(b-ave,2))+(pow(c-ave,2))+(pow(d-ave,2))+(pow(e-ave,2)))/5;  
  11.     y = (pow(x,(0.5)));  
  12.   printf("平均值:%.2f\n",ave);  
  13.   printf("變異數:%.2f\n",x);  
  14.   printf("標準差:%.2f\n",y);  
  15.   system("PAUSE");    
  16.   return 0;  
  17. }  

Hiç yorum yok:

Yorum Gönder

Binary Conversion

Problem Description Convert two binary numbers into two decimal numbers and compute their sum. Your program has to convert two binary number...