Jump to content

C++ Standart Sapma Yanlış Hesaplıyor


DrMakarna_
 Share

Recommended Posts

kodun elle girilen veya rastgele programın atadığı dizinin standart sapmasını ve ortalamasını alması gerekiyor virgüllü sayılarda da ama standart sapmayı yanlış hesaplıyor anlayan varsa bakabilir misiniz.

 

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include<string.h>

float StandartSapma(float dizi[],int boyut);
int main(){
    
    int secim =0,boyut=0,min=0,maks=0;
    float dizi[100];
    float ortalama=0.0, toplam=0.0;
    
    
    printf("\nDizi nasil olusturulacak?");
    printf("\n1. Rastgele sayilarla");
    printf("\n2. Elle konsoldan girilecek\n");
    scanf("%d", &secim);
    
    if(secim == 1){
        printf("Kac adet sayi olusturulsun?\n");
        scanf("%d",&boyut);
        printf("Hangi araliklarda olusturulsun?\n");
        printf("Minimum : ");
        scanf("%d",&min);
        printf("Maksimum : ");
        scanf("%d",&maks);
        for(int i=0;i<boyut;i++){
            int sayi = ((min)+rand()%(maks+1-min));
            dizi = sayi;
            toplam += dizi;
        }
        for(int i=0;i<boyut;i++){
            printf("%.f ",dizi);
        }
        ortalama =(float) toplam / boyut;
        
        printf("\nOrtalama= %.2f", (float)ortalama);
        printf(" Standart Sapma = %.2f",StandartSapma(dizi,boyut));
    }
    else if(secim == 2){
        printf("Kac adet sayi girilecek?\n");
        scanf("%d",&boyut);
        printf("Lutfen sayilari girin: ");
        for(int i =0;i<boyut;i++){        
            scanf("%f", &dizi);
            toplam += dizi;
        }
        ortalama = toplam / boyut;
        printf("Ortalama= %.2f", ortalama);
        printf(" Standart Sapma = %.2f", StandartSapma(dizi,boyut));    
    }

}

float StandartSapma(float dizi[],int boyut)
{
    float toplam1 = 0.0, ortalama1, ssapma = 0.0;
    for(int i=0; i<boyut; ++i)
        toplam1 += dizi;
          
    ortalama1 = toplam1/boyut;

    for(int i=0; i<boyut; ++i)
        ssapma += pow(dizi - ortalama1, 2);

    return sqrt(ssapma/boyut);
}

 

Untitled12.cpp

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...