Showing mean and variance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guiromero
    New Member
    • Nov 2021
    • 4

    Showing mean and variance

    Hello!

    I'm writing a program that calculates and shows the mean and variance of two integers. The result I'm getting is 7. But that's not the mean of 5 and 10 (num1 and num2). What can I do to show both mean and variance together on the screen? What should I put after return to get both mean and variance?

    Thank you.

    #include <stdio.h>


    double statistics (int x, int y){

    double mean, var;

    mean = (x+y)/2;
    var = ((x-mean)*(x-mean) + (y-mean)*(y-mean)) /2;

    return mean;
    }

    int main(){

    int num1, num2;

    num1 = 10;
    num2 = 5;


    printf("%lf", statistics(num1 , num2));

    return 0;
    }
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    I'm writing a program that calculates and shows the mean and variance of two integers. The result I'm getting is 7. But that's not the mean of 5 and 10 (num1 and num2).
    Code:
    (x+y)/2
    produces int type result.

    What can I do to show both mean and variance together on the screen? What should I put after return to get both mean and variance?
    A function can return one value. Write separate functions or print both from a function.

    Comment

    • iamsteve03
      New Member
      • Dec 2021
      • 1

      #3
      int type return, nice one, error-free code

      Comment

      Working...