Created
October 6, 2010 06:53
-
-
Save kaldas/612923 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /******************************************* | |
| Processo e Desenvolvimento de Software | |
| Aluno: rodrigo caldas de moura duarte | |
| gcc test1.c -o test1 -lm;./test1 | |
| *******************************************/ | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <math.h> | |
| /* retorna desvio padrao */ | |
| double stdev(int buff[], int bfsize) | |
| { | |
| int cnt = 0; | |
| double aqr = 0, mean = 0, dif = 0; | |
| for(cnt=0;cnt != bfsize;cnt++) | |
| mean += buff[cnt]; | |
| mean = mean / cnt; | |
| for(cnt=0;cnt != bfsize;cnt++) | |
| { | |
| dif = buff[cnt] - mean; | |
| aqr += (dif * dif); | |
| } | |
| aqr = (double) aqr / (bfsize - 1); | |
| return sqrt(aqr); | |
| } | |
| /* exemplo de uso */ | |
| int main() | |
| { | |
| int *buff, bfsize = 0, cnt = 0; | |
| fprintf(stdout,"\nDe quantos elementos deseja tirar a media e o desvio? "); | |
| scanf("%i",&bfsize); | |
| buff = (int *) calloc(bfsize, sizeof(int)); | |
| if(!buff || bfsize == 0) | |
| { | |
| fprintf(stderr,"erro de memoria ou entrada nula\n"); | |
| return -1; | |
| } | |
| for(cnt = 0; cnt != bfsize; cnt++) | |
| { | |
| printf(" \nEntre com a [%i] entrada.. : ",cnt + 1); | |
| scanf("%i",buff+cnt); | |
| } | |
| fprintf(stdout," Standard Variation: %f \n",stdev(buff,bfsize)); | |
| //system("pause"); //aff windows babaca | |
| free(buff); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment