Question

2. Write a C program that using arrays A and B calculates the given formula. The program should save the results in the Carra2. Write a program that using arrays A and calculates the given tornog Save the results in the Carray and then print int All

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<stdio.h> int main(){ //given int A[7] = { 215,431,25,64,18,99,105}; int B[7] = { 50,78,31,477,22,258,312}; int A_copy[7] , B_copy[7]; //copy elements of A in A_copy and elements of B in B_copy for (int k = 0; k < 7; ++k) { A_copy[k] = A[k]; B_copy[k] = B[k]; } //lets find median of array A and B // first we need to sort //using bubble sort to sort arrays int temp ; for (int i = 0; i < 7; ++i) { for (int j = 0; j < 7-i-1; ++j) { if( A_copy[j] > A_copy[j+1 ]){ //swap both elem temp = A_copy[j]; A_copy[j] = A_copy[j+1] ; A_copy[j+1] = temp ; } } } // similarly find B_sort for (int i = 0; i < 7; ++i) { for (int j = 0; j < 7-i-1; ++j) { if( B_copy[j] > B_copy[j+1 ]){ //swap both elem temp = B_copy[j]; B_copy[j] = B_copy[j+1] ; B_copy[j+1] = temp ; } } } int mid_a , mid_b; //median element will be the 4th element in the array mid_a= A_copy[3]; mid_b = B_copy[3]; double C[7]; for (int i = 0; i < 7; ++i) { C[i] = (double)((A[i] + B[i])*2)/(double)(mid_a + mid_b); } //print contents of array C printf("Contents of array C are as follows : \n"); for (int m = 0; m < 7; ++m) { printf("%f\t" , C[m]); } } 

Contents of array C are as follows: 2.994350 5.751412 0.632768 6.112994 Process finished with exit code o 0.451977 4.033898 4

Add a comment
Know the answer?
Add Answer to:
2. Write a C program that using arrays A and B calculates the given formula. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study...

    c/c++ Passing arrays as arguments to functions. The main() is given, write the function 'average' (Study the syntax of passing an array as a function parameter) The program prompts the user to first enter the number of tests given in a course, and then prompts him/her to enter the mark for each test. The marks are stored in an array. This takes place in the main() function. It then passes the array to a function named 'average' that calculates and...

  • For c++ Write a complete C++ program and declare 2 arrays type double size 5. The...

    For c++ Write a complete C++ program and declare 2 arrays type double size 5. The name of the first array is Salary and the name of the second array is Tax. Use a for loop loop and enter 5 salaries type double into array Salary. Then multiply each element of array Salary by .10 (10 percent), and save the result into array Tax. Print/display the content of both arrays. Hint: the content of array Tax is 10% percent of...

  • I need this ASAP Write a SIC assembly program that calculates a+b/c Save the result to...

    I need this ASAP Write a SIC assembly program that calculates a+b/c Save the result to a. Use the example program in the textbook page 47 as reference.

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • c++ help Write a program that: Creates two finite arrays of size 10 These arrays will...

    c++ help Write a program that: Creates two finite arrays of size 10 These arrays will serve as a storing mechanism for student grades in Classes A and B Uses a loop to populate the arrays with randomly generated numbers from 0 to 100.These numbers will represent student grades. Compute average grade of each class. Finally, output the two arrays and the message with two averages and best class. ("Class A average is: 65.43; class B average is: 68.90. Class...

  • write a c program for the above Write a program which prompts the user to enter...

    write a c program for the above Write a program which prompts the user to enter three integers (data type int) and then calculates the arithmetic average as a decimal number and prints the value with two decimal digits. If you have time also calculate and print the harmonic mean of the same numbers according to the following formula: 3. PT harmonic _mean-1 1 22x (Test with integer values of 4, 7, and 8. You may submit one program per...

  • Write a C program that reads the height and weight of a person and calculates the...

    Write a C program that reads the height and weight of a person and calculates the body mass index (bmi) according to formula bmi = weight/(height)2. Your program should display a qualitative assessment of the weight according to the following table: BMI value Letter Grade [0-20) Below normal weight [20-25) Normal weight [25-30) Overweight >=30 Obese Sample Output: Enter your weight in kilos: 70 Enter your height in meters: 1.80 Result: Normal weight Test values: (70 1.8) (50, 1.9) (90,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT