Find Coefficient of Variation

 
post-image


//compute the value of the coefficient of variation of runs scored by two Cricketers A and B to compare their batting performance in last 10 innings



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

main()
{
    int ikNa[20], b[20];
    float sumA = 0sumB = 0sAsBmeanAmeanBm2Am2BsdA
        sdBcvAcvB;
    
    printf("Enter the number of innings:\n");
    scanf("%d", &N);
    
    printf("\nEnter the batting records of Cricketer A:>\n");
    for (i = 0i < Ni++)
    {
        printf("Runs scored in innings %d= "i + 1);
        scanf("%d", &a[i]);
        sumA += a[i];
    }
    meanA = sumA / N;
    
    printf("\nEnter the batting records of Cricketer B:>\n");
    for (i = 0i < Ni++)
    {
        printf("Runs scored in innings %d= "i + 1);
        scanf("%d", &b[i]);
        sumB += b[i];
    }
    meanB = sumB / N;
    
    for (i = 0i < Ni++)
    {
        sA += pow(a[i] - meanA2);
        sB += pow(b[i] - meanB2);
    }
    
    m2A = sA / N;
    m2B = sB / N;
    sdA = sqrt(m2A);
    sdB = sqrt(m2B);
    cvA = sdA / meanA;
    cvB = sdB / meanB;
    
    printf("\nThe Coefficient of Variation of Cricketer A is %f"
        cvA);
    printf("\nThe Coefficient of Variation of Cricketer B is %f"
        cvB);
    
    if (cvA > cvB)
        printf("\n\nComment: Cricketer B is more consistent than 
            Cricketer A");
    else
        printf("\n\nComment: Cricketer B is more consistent than 
            Cricketer A");
}



Output:
Enter the number of innings:
10

Enter the batting records of Cricketer A:>
Runs scored in innings 1= 26
Runs scored in innings 2= 97
Runs scored in innings 3= 6
Runs scored in innings 4= 112
Runs scored in innings 5= 89
Runs scored in innings 6= 5
Runs scored in innings 7= 6
Runs scored in innings 8= 108
Runs scored in innings 9= 24
Runs scored in innings 10= 16

Enter the batting records of Cricketer B:>
Runs scored in innings 1= 51
Runs scored in innings 2= 47
Runs scored in innings 3= 36
Runs scored in innings 4= 60
Runs scored in innings 5= 58
Runs scored in innings 6= 39
Runs scored in innings 7= 44
Runs scored in innings 8= 42
Runs scored in innings 9= 71
Runs scored in innings 10= 50

The Coefficient of Variation of Cricketer A is 0.896790
The Coefficient of Variation of Cricketer B is 0.203951

Comment: Cricketer B is more consistent than Cricketer A