Question

In: Computer Science

The following program is supposed to read 10 pairs of 2D coordinates, (xi , yi ),...

The following program is supposed to read 10 pairs of 2D coordinates, (xi , yi ), and print the average coordinate. However, it does not work correctly. Fix the program so that it compiles with no errors or warnings and correctly computes the average coordinate.

int main() {
    float coords[9][2] = { 0 };
    float sum[2];

    while (i < 2) {
        scanf("%d%d", &coords[i][0], coords[i][1]);
        sum[0] += coords[i][0];
        sum[1] += coords[i][1];
    }

    printf("Average coordinate: (%.2d, %.2d)\n", sum[0], sum[1]);

    return 0;
} 

Need it in 10 minutes, please.

Solutions

Expert Solution

#include<stdio.h>
int main() {
    float coords[9][2] = { 0 };
    float sum[2];
    int i=0;
    while (i < 10) {
        scanf("%f%f", &coords[i][0], &coords[i][1]);
        sum[0]+= coords[i][0];
        sum[1]+= coords[i][1];
        i+=1;
    }
    
    printf("Average coordinate: (%.2f,%.2f)\n",(sum[0]/10),(sum[1]/10));
    return 0;
} 

The above is the program that will calculate the average of the 10 pair of 2d coordinate and pritns the output.The program asks the user to enter space seperated number for 10 times and then it iwll print the average of the numbers.

SCREENSHOT OF THE OUTPUT :

EXPLAINATION OF THE PROGRAM ERRORS :

int main() {
    float coords[9][2] = { 0 };
    float sum[2];

    while (i < 2) {    //HERE WE ARE USING I DUT THE I IS NOT DECLARED AND ALSO INORDER TO 
                       //ENTER 10 VALUES WE NEED TO USE I <10
        
scanf("%d%d", &coords[i][0], coords[i][1]); //%d%d BUT FOR FLOAT WE NEED TO USE %f%f
                                                  //SO WE GET AN WARNING
        sum[0] += coords[i][0];
        sum[1] += coords[i][1];
    }

    printf("Average coordinate: (%.2d, %.2d)\n", sum[0], sum[1]); //here we have float output
                      //then we need to use %.2f,%.2f but we are using %.2d,%.2d so we get an                                
                      //warning.(HEre we are using %.2f inorder to restrict output to 2 
                      //values)

    return 0;
} 

**************************************PLEASE ENCOURAGE US WITH AN OUTPUT***************************************


Related Solutions

We have a dataset with n = 10 pairs of observations (xi; yi), and Xn i=1...
We have a dataset with n = 10 pairs of observations (xi; yi), and Xn i=1 xi = 683; Xn i=1 yi = 813; Xn i=1 x2i = 47; 405; Xn i=1 xiyi = 56; 089; Xn i=1 y2 i = 66; 731: What is the line of best t for this data?
The following 12 data pairs relate variable xi, the amount of fertilizer, to variable Yi, the...
The following 12 data pairs relate variable xi, the amount of fertilizer, to variable Yi, the amount of wheat harvested: x: 30 30 30 50 50 50 70 70 70 90 90 90 Y: 9 11 14 12 14 23 19 22 31 29 33 35 such that : ∑x = 720 ∑y = 252 , ∑ xy =17240, ∑x2 =49200, ∑y2 = 6228 a) Find equation of linear regression line: Y = A + BX. b) 95% 2 sided...
Consider the following data to be used in a regression. xi yi 1 0 2 10...
Consider the following data to be used in a regression. xi yi 1 0 2 10 3 25 4 30 5 35 (a) Find the values of b0 and b1. (b) Find the Coefficient of Determination. (c) Find the estimated standard deviation of b1 and the corresponding t-statistic. At the 1% level of significance, can you reject the null hypothesis? Make sure you state the null and alternative hypotheses. (d) Find the F-statistic. Is the equation significant at the 1%...
Following is a simple linear regression model: yi = /alpha + /beta xi + /epsilon i...
Following is a simple linear regression model: yi = /alpha + /beta xi + /epsilon i The following results were obtained from some statistical software. R2 = 0.735 syx (regression standard error) = 5.137 n (total observations) = 60 Significance level = 0.05 = 5% Variable Parameter Estimate Std. Err. of Parameter Est. Interecpt 0.325 0.097 Slope of X -1.263 0.309 1. Write the fitted model. (I ALREADY KNOW THE ANSWER TO THIS. I LEFT IT INCASE IT IS NEEDED...
Java Code Question: The program is supposed to read a file and then do a little...
Java Code Question: The program is supposed to read a file and then do a little formatting and produce a new txt file. I have that functionality down. My problem is that I also need to get my program to correctly identify if a file is empty, but so far I've been unable to. Here is my program in full: import java.io.*; import java.util.Scanner; public class H1_43 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter...
Read the case study, then answer the questions that follow. Leanne coordinates a support program for...
Read the case study, then answer the questions that follow. Leanne coordinates a support program for parents of children recently diagnosed with developmental disabilities. The program includes information sessions, peer support groups, and referrals to early intervention and therapy services. One of Leanne’s group facilitators, Lois, has come to see her because she is concerned about one of the mothers in her group. Mrs. Smith has a 10-month-old baby with Down’s syndrome. The baby is difficult to settle, has always...
Consider the data. xi 2 6 9 13 20 yi 7 17 10 28 24 (a)...
Consider the data. xi 2 6 9 13 20 yi 7 17 10 28 24 (a) What is the value of the standard error of the estimate? (Round your answer to three decimal places.) _________ (b) Test for a significant relationship by using the t test. Use α = 0.05. State the null and alternative hypotheses. H0: β0 = 0 Ha: β0 ≠ 0 H0: β1 = 0 Ha: β1 ≠ 0     H0: β0 ≠ 0 Ha: β0 = 0...
Consider the data. xi 1 2 3 4 5 yi 3 7 5 10 13 (a)...
Consider the data. xi 1 2 3 4 5 yi 3 7 5 10 13 (a) Compute the mean square error using equation s2 = MSE = SSE n − 2  . (Round your answer to two decimal places.) (b) Compute the standard error of the estimate using equation s = MSE = SSE n − 2  . (Round your answer to three decimal places.) (c) Compute the estimated standard deviation of b1 using equation sb1 = s Σ(xi −...
Consider the data. xi 3 12 6 20 14 yi 55 35 45 10 15 The...
Consider the data. xi 3 12 6 20 14 yi 55 35 45 10 15 The estimated regression equation for these data is ŷ = 62.25 − 2.75x. (a) Compute SSE, SST, and SSR using equations SSE = Σ(yi − ŷi)2, SST = Σ(yi − y)2, and SSR = Σ(ŷi − y)2. SSE= SST= SSR= (b) Compute the coefficient of determination r2.(Round your answer to three decimal places.) r2 = Comment on the goodness of fit. (For purposes of this...
7 7. The following 12 data pairs relate variable xi, the amount of fertilizer, to variable...
7 7. The following 12 data pairs relate variable xi, the amount of fertilizer, to variable Yi, the amount of wheat harvested:                                  x: 30 30 30 50 50 50 70 70 70 90 90 90                     Y: 9 11 14 12 14 23 19 22 31 29 33 35                                                         such that : ∑x = 720   ∑y = 252 ,   ∑ xy =17240,    ∑x2 =49200,      ∑y2 = 6228 a) Find equation of linear regression line: Y = A + BX....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT