Question

Write the full C program which implements the operations given below using pointers. • Define an...

Write the full C program which implements the operations given below using pointers. • Define an array of integers (x array). • The size of the array will be 100. • x values will be randomly determined between 1 and 20. • Set the seed of the random number generator to the system time. • Define the external function => y = x2 + 3x + 5 • Calculate and save the results (y values) of the function to another array. • Sort x-y pairs with respect to x values. • Save x-y pairs to a sequential file.

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

Solution:
Look at the ode and comments for better understanding...............

Screenshot of the code:

-/QA/c/solution.c.- Sublime Text (UNREGISTERED) Project Preferences Help File Edit Selection Find View Goto Tools solution.c

Output:

I am writing the results to a file output.txt you can use the name of your own

gm@Tricia: -/QA/C File Edit View Search Terminal Help gm@Tricia:-/QA/c$ gcc solution.c gm@Tricia:-/QA/c$ ./a.out gm@Tricia:-/

Code:

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//function that returns tha value of y corresponding to x
int y(int x){
        return (x*x)+(3*x)+5;
}
int main(){
        //Defining x_array and y_array of size 100
        int *x_array=(int *)malloc(sizeof(int)*100);
        int *y_array=(int *)malloc(sizeof(int)*100);
        //seeding the rand() function with time
        srand(time(0));
        //placing values in x_array
        for(int i=0;i<100;i++){
                //generating a random number between 1 and 20
                *(x_array+i)=(rand()%20)+1;
        }
        //placing values in y_array
        for(int i=0;i<100;i++){
                *(y_array+i)=y(*(x_array+i));
        }

        //Writing to a file
        //I am writin the value of x and y (x,y) but you can use the format you like
        FILE *fp=fopen("output.txt","w");
        for(int i=0;i<100;i++){
                fprintf(fp,"(%d,%d) ",*(x_array+i),*(y_array+i));
        }
        fclose(fp);
}

I hope this would help you..........................:-))

Please provide feedback...................:-))

Add a comment
Know the answer?
Add Answer to:
Write the full C program which implements the operations given below using pointers. • Define an...
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
  • Write a program that meets the following criteria: Define a function that implements the selection sort...

    Write a program that meets the following criteria: Define a function that implements the selection sort algorithm to sort an integer array. Define a function that implements the binary search algorithm to search an array for a given integer. The function must return the location of the integer if it is found or a -1 if it is not found. The main function in your program must declare an integer array initialized with 10 unsorted values. The main function must...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • 29. (20 points) Write the complete C++ program that implements the following program, as if you...

    29. (20 points) Write the complete C++ program that implements the following program, as if you were turning this in for homework. Your program should have a commented header (your name, etc), comments within the program and a well-built display for the output. Don't forget the pre-processor commands Define an array called nums with a maximum of 20 integers, and fill the array with numbers, recei the keyboard (prompt for the numbers.) In this program, exactly 20 integers will be...

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • Write an object-oriented C++ program (i.e. a class and a main function to use it), using...

    Write an object-oriented C++ program (i.e. a class and a main function to use it), using pointer variables, that program that performs specific searching and sorting exercises of an array of integers. This program has six required outputs. Start by initializing an array with the following integers, in this order: 23, 17, 5, 90, 12, 44, 38, 84, 77, 3, 66, 55, 1, 19, 37, 88, 8, 97, 25, 50, 75, 61, and 49. Your array input may be hardcoded...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your...

    PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your solution. Readability of the program will be graded based on variable naming, indentation, commenting (not too little and not too much), spacing, consistency, and styling in general including choice of functions. [NOTE: the code at the end of this document does not completely meet requirements as it uses many single letter variables and has no internal documentation. You need to improve it.] 2. Compile...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

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