Question

In: Computer Science

use repil.it edit my code please i already did all part but need to edit more...

use repil.it edit my code please i already did all part but need to edit more its run for some not shwing all

intro to C-programin be sure to edit on my code very basic and add good comments thank you

1-Write a program that requests 5 integers from the user and stores them in an array. You
may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input in each spot in the array.

2-Add a function to the program, called get_mean that determines the mean, which is the average of the values. The function should be passed the array and the size of the array, but use const so that it cannot be changed, only accessed. It should return a double, which is the calculated mean. The main function will print the value.

//Function prototype:
double get_mean(const int [], int);

3-Create a function called search_array that searches the array for the answer to life, the universe, and everything - the integer 42. If 42 is found, print You wrote The Answer to the Great Question!. If it is not found, print You might not know the answer to Life, the Universe, and Everything. Set a global variable called search_for to store the number to search for (42)

//Function prototype:
void search_array(const int [], int);

4-Create a function called sort_array. The array should be sorted in descending order. The function should be passed the array and the size of the array. The function does not return a value; the array is changed by the function. The main function will print the sorted array (you may create a print array function if desired).

//Function prototype:
void sort_array(int [], int);

**{note} from teacher need to edit

Why are you creating the const array

If you make it const you can't change the elaments.

For size calc use the function sizeof()

you have declare search_for as global variable

in the below statement "void search_array(const my_array[],int size){" you have to give datatype of array.

variable temp scope is main function, you need to declare the temp variable in sort_array()

_____________________________________________\

/

//libraries

//files that we need to include

#include

#include

#include

//Function prototype:

double get_mean(const int [], int);

void search_array(const int [], int);

void sort_array(int [], int);


int main(void){

int my_array[5];

//input requesting from user

printf("Please Enter 5 integers, hit enter after each input:\n");

//for loop to get input

for(int i=0; i<5; i++){

scanf("%d",&my_array[i]);

}

//function call for mean of the integer

double m=get_mean(my_array,5);

//print mean

printf("The mean of array is:%.2f\n",m);

search_array(my_array,5);

sort_array(my_array,5);

printf("Array sorted in order: ");

return 0;

}

//function definition to get_mean

double get_mean(const int my_array[],int size){

double sum=0.0;

for(int i=0; i

//calculate to get mean

sum+=my_array[i];

}

double get_mean = sum/size;

return get_mean;

}

//function definition to search_array

void search_array(const int my_array[], int size){

int search_for = 42;

for(int i=0;i

if(my_array[i]==search_for){

//found

printf("You wrote The Answer to the Great Question!\n");

return;

}

}

//not found

printf("You might not know the answer to Life, the Universe, and Everything\n");

}

// Function to print an array

void printArray(int my_array[], int size)

{

int i;

for (i = 0; i < size; i++)

printf("%d ", my_array[i]);

printf("\n");

}

// Function to Sort array

void sort_array(int my_array[], int size){

int temp;

for(int i=0;i

for (int j=i+1;j

if (my_array[i] > my_array[j]){

temp=my_array[i];

my_array[i]=my_array[j];

my_array[j]=temp;

}

}

}

}

Solutions

Expert Solution

//libraries file that we need to include

#include<stdio.h>


//Function prototype:
double get_mean(const int [], int);
void search_array(const int [], int);
void sort_array(int [], int);
void printArray(int [], int );

int search_for;

int main(void)
{
    int my_array[5],size;
    double m;
    //input requesting from user
    printf("Please Enter 5 integers, hit enter after each input:\n");
    for(int i=0; i<5; i++)      //for loop to get input
    {
        scanf("%d",&my_array[i]);
    }
    size=sizeof(my_array)/sizeof(my_array[0]);              //Using sizeof() function to calculate the size of the array

    m=get_mean(my_array,size);      //Calling get_mean() function to get the mean of the array
    printf("The mean of the array is:%lf\n\n",m);        //printing mean

    search_array(my_array,size);           //Calling search_array() function to search for the global variable

    sort_array(my_array,size);              //Calling sort_array() function to sort the array

    printf("Array sorted in order: ");      //Printing the sorted array
    printArray(my_array,size);              //Calling printArray() function to print the array

    return 0;
}

//function to calculate mean
double get_mean(const int my_array[],int size)
{
    int sum=0;
    for(int i=0; i<size;i++)
        sum+=my_array[i];       //calculate to get mean

    double get_mean = (double)sum/size;
    return get_mean;
}

//function to search for 42
void search_array(const int my_array[], int size)
{
    search_for = 42;            //Setting the global variable search_for to 42
    int flag=0;
    for(int i=0;i<size;i++)
    {
        if(my_array[i]==search_for)
        {
            //found
            flag=1;
            break;
        }
    }
    if(flag==1)
        printf("You wrote The Answer to the Great Question!\n\n");            // found
    else
        printf("You might not know the answer to Life, the Universe, and Everything\n\n");    //not found
}


// Function to print array
void printArray(int my_array[], int size)
{
    int i;
    for (i = 0; i < size; i++)
        printf("%d ", my_array[i]);
    printf("\n");
}

// Function to Sort array
void sort_array(int my_array[], int size)
{
    int temp;
    //Sorting in descending order
    for(int i=0;i<size;i++)
    {
        for(int j=i+1;j<size;j++)
        {
            if (my_array[i] < my_array[j])
            {
                temp=my_array[i];
                my_array[i]=my_array[j];            //Swapping my_array[i] and my_array[j]
                my_array[j]=temp;
            }
        }
    }
}

The ouput :

PLEASE LIKE THE ANSWER IF YOU FIND IT HELPFUL OR YOU CAN COMMENT IF YOU NEED CLARITY / EXPLANATION ON ANY POINT.


Related Solutions

JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to use all methods, also switch statements. Write a Temperature class. The class will have three conversion methods: toCelsius(), toKelvin() and toFahrenheit(). These methods will return a Temperature in those three scales equal to the this temperature. Note that the value of this is not changed in these conversions. In addition to these three conversion methods the class will have methods add(Temperature), subtract(Temperature), multiply(Temperature), and...
I need to understand how I would edit this code without changing anything, only adding. I...
I need to understand how I would edit this code without changing anything, only adding. I am not looking for the exact answer, just information on how I would use the given code to complete some of the todo statements. Thank you! // include this header file so we can use `printf()` #include <stdio.h> // every C program must implement the `main()` function int main(int argc, char *argv[]) {    //TODO: check for enough arguments       // save the...
PLEASE ONLY DO THE LAST PORTION " Final Questions." I already did all the other ones....
PLEASE ONLY DO THE LAST PORTION " Final Questions." I already did all the other ones. Your friend, another accountant, has bet you that with your knowledge of accounting and just the computations for common analytical measures, you can figure out many aspects of a company's financial statements. You take the bet! Match each computation to one of the liquidity and solvency measures in the table. (Hint: Begin by looking for simple computations and identifying the amounts in those computations....
I haves code on bottom. what do i need to edit? Create a subdirectory called proj1.  For...
I haves code on bottom. what do i need to edit? Create a subdirectory called proj1.  For this project you need to create at least two files: proj1.cpp, and makefile. Both files should be placed in the proj1 directory. The file proj1.cpp should contain the main function, int main(). In the main() function, the program should read the input until it reaches the end, counting the number of times each word, number, and character is used. A word is defined as a sequence of letters ('a'..'z' or 'A'..'Z')....
Please edit, rephrase or add something to the following part of my report. Question:Whether debt funding...
Please edit, rephrase or add something to the following part of my report. Question:Whether debt funding would be desirable, or even possible for the new equipment required should the company decide to pursue aggressive expansion – noting that the equipment used by the business is quite specialised and cannot easily be sold and taken to another company. Answer:Debt funding is not adviseable as these assets are specialised and resale would not be easy .An Operating lease option would be preferred...
FOR THE SCENARIO BELOW...I need to know if my hypotheses are directional or non-directional.(I already have...
FOR THE SCENARIO BELOW...I need to know if my hypotheses are directional or non-directional.(I already have the hypotheses) I know I need to use a two sample T test but need help with the calculations. (Provide a sample size and critical values in relation to the hypothesis.) -Discuss what the statistical analysis will do in answering the hypotheses and question(s) for the client. Also discuss any potential problems to watch out for, including an appropriate sample size to meet the...
So pretty much I need my code without the arrays, or lists. Please and thank you!...
So pretty much I need my code without the arrays, or lists. Please and thank you! Important: You may not use arrays, lists, or similar for your questions. This will be covered in the next module. The objective is to use conditionals in order to achieve the overall task. Checkpoint 3 is a continuation of the “Quiz” Programming Project. This module week, you will implement repetitive tasks in your program while using conditional and iteration statements in C#. Implement a...
Good morning, Yes I did post part a Someone answered part (a) and (c) already. Here...
Good morning, Yes I did post part a Someone answered part (a) and (c) already. Here is the answered part (A). Can you complete part B please Thank you Here is part (A) again Comprehensive Problem 5 Part A: Note: You must complete part A before completing parts B and C. Genuine Spice Inc. began operations on January 1 of the current year. The company produces 8-ounce bottles of hand and body lotion called Eternal Beauty. The lotion is sold...
i need a conclusion for my paper on ADHD. I need this asap please have to...
i need a conclusion for my paper on ADHD. I need this asap please have to turn my paper in one hour!!!! thank you            In the recent times, ADHD is being seen in the light of cerebral dysfunction with too much focus on clinical treatment using medication at the same time keeping psychotherapy at bay which shows a dangerous trend. Psychotherapy even though cannot explain the cause of the condition, but it can help the children in coping his...
Financial Statements ( I need last part (4) as sson as possible) please do all part...
Financial Statements ( I need last part (4) as sson as possible) please do all part thanks Jose Loder established Bronco Consulting on August 1, 2019. The effect of each transaction and the balances after each transaction for August follow: Assets = Liabilities + Owner's Equity Cash + Accounts Receivable + Supplies = Accounts Payable + Jose Loder Capital - Jose Loder Drawing + Fees Earned - Salaries Expense - Rent Expense - Auto Expense - Supplies Expense - Misc....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT