Question

PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU!

Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #in

Task 3: Define a function called average Difference( ) that takes two arrays of int as the parameters, calculate the differen

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#define SIZE 9 //declaring macro value
#include<stdio.h> 
//declaring functions here
int compareAndCount(int[],int[]);
double averageDifference(int[],int[]);
//driver function
void main()
{
    int a1[SIZE],a2[SIZE],count=0; //taking a1 for array A a2 for array B
    double avg=0.0;
    printf("Enter elements of array A:\n");
    for(int i=0;i<SIZE;i++) 
    {
        scanf("%d",&a1[i]);//inserting elements in array A
    }
    printf("Enter elements of array B:\n");
    for(int i=0;i<SIZE;i++) 
    {
        scanf("%d",&a2[i]);//inserting elements in array B
    }
    count = compareAndCount(a1,a2); //calling compareAndCount() function and passing a1 and a2
    printf("Number of items in array A greater than the corresponding items in array B: %d",count);//printing count value
    avg = averageDifference(a1,a2); //calling averageDifference() function and passing a1 and a2
    printf("\nThe average difference between items in the array A and array B: %0.2lf",avg); //printing avg
}
//function defined here for compareAndCount()
int compareAndCount(int arr1[SIZE],int arr2[SIZE])
{
    int count=0;
    for(int i=0;i<SIZE;i++)
    {
        if(arr1[i]>arr2[i]) //condition to check element of arr1 is greater than arr2
        {
            count++; //if condition is true increment count value each time
        }
    }
    return count; //returning value of count
}
//function defined here for averageDifference()
double averageDifference(int arr1[SIZE],int arr2[SIZE])
{
    double average;
    int sum=0;
    int temp[SIZE];
     for(int i=0;i<SIZE;i++)
    {
        temp[i] = arr1[i] - arr2[i];
        printf("\narr1[%d] - arr2[%d]: %d",i,i,temp[i]); //subtrating each corresponding elements of both arrays and assigning it to temp array
    }
    
    for(int i=0;i<SIZE;i++)
    {
        sum = sum + temp[i]; //calculating summ of all the elements in the array
    }
    average = (double)sum/SIZE; //calculating average value of the elements in the array
    return average; //returning the value of average
}

Output:

sequel Enter elements of array A: ile 12 12 151 24 62 32 e12 8 9 Enter elements of array B: 56 87 5 23 4 17 89 5 1 Number of

Flowchart:

According to the source code there will three flowchart for every function - main function , compareAndCount function, Averagedifference function.

Main function-

Start int SIZE = 9 int a 1[SIZE],a2[SIZE] int count=0 double avg=0.0 inti print Enter elements of array A: i = 0 Loop i<SIZE

compareAndCount function

compareAndCount(int arr1[SIZE], int arr2[SIZE]) int count = 0 int i = 0 Loop i<SIZE arr1[i] > arr[2] count++ return count

averageDifference function

i = 0 Loop < SIZE return average

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Given...
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
  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint: the number array in task 2 is work for task 3 in figure 1.   Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i...

  • Given below is a partially completed C program, which you will use as a start to...

    Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count - @; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; return count; Task 1: (10 pts) Show the design of the function compareAndCount() by writing a pseudocode. To...

  • I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a...

    I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = @; for (int i = 0; i < SIZE; i++) { if (arr1[1] > arr2[i]) count++; return count; } Task 1: (10...

  • I need this program converted to c++ Please help if you can import java.util.*; // Add...

    I need this program converted to c++ Please help if you can import java.util.*; // Add two arrays of the same size (size) // Each array is a representation of a natural number // The returned array will have the size of (size + 1) elements public class Fibonacci { private static String arrToString(int[] arr) {           String s = "";           for (int i = 0; i < arr.length; i++) {               s = s + arr[i];           }...

  • COULD YOU PLEASE HELP ME************************** write a better mode computation function that uses the ideas in...

    COULD YOU PLEASE HELP ME************************** write a better mode computation function that uses the ideas in the word file and improves on the mode computation function in the cpp file. ===========source.cpp #include <ctime> #include <iomanip> #include <iostream> #include <string> #include <random> using namespace std; default_random_engine e(static_cast<unsigned>(time(NULL))); void fill(int a[], int size, int value) { for(int i = 0; i < size; i++) a[i] = value; } void randomFill(int a[], int size, int lb, int up) { uniform_int_distribution<int> u(lb, up); for(int...

  • Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the...

    Hi this is C++, I'm really struggle with it please help me.... ************************ Here is the original high score program,: Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score. The output from your program should look exactly like this: Enter the name for score #1: Suzy Enter the score for...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

  • guys can you please help me to to write a pseudo code for this program and...

    guys can you please help me to to write a pseudo code for this program and write the code of the program in visual studio in.cpp. compile the program and run and take screenshot of the output and upload it. please help is really appreciated. UTF-8"CPP Instruction SU2019 LA X 119SU-COSC-1436- C Get Homework Help With Che X Facebook -1.amazonaws.com/blackboard.learn.xythos.prod/584b1d8497c84/98796290? response-content-dis 100% School of Engineering and Technology COSC1436-LAB1 Note: in the instruction of the lab change "yourLastName" to your last...

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