1 answer

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

Question:

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.


Answers

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...................:-))

.

Similar Solved Questions

1 answer
Exercise 2-7 Job-Order Costing; Working Backwards [LO2-1, LO2-2, LO2-3] Hahn Company uses a job-order costing system....
Exercise 2-7 Job-Order Costing; Working Backwards [LO2-1, LO2-2, LO2-3] Hahn Company uses a job-order costing system. Its plantwide predetermined overhead rate uses direct labor-hours as the allocation base. The company pays its direct laborers $15 per hour. During the year, the company started and ...
1 answer
Feherty, Inc., accounts for its investments under IFRS No. 9 and purchased the following investments during...
Feherty, Inc., accounts for its investments under IFRS No. 9 and purchased the following investments during December 2021: 1. One hundred and sixty of Donald Company's $1,000 bonds. The bonds pay semiannual interest, return principal in 10 years, and include no other cash flows or other features...
1 answer
ARCTIC COMPAY Income Statement For the Tear tnded December 31, 2013 Sales evenue S0000 Cest of...
ARCTIC COMPAY Income Statement For the Tear tnded December 31, 2013 Sales evenue S0000 Cest of Goods Sold 587400 Wges Expense 209.000 Advertiong xperoe 34100 Deprecation Expere ntwpense 24200 1900 Gain on Sale ef Land 27500 47000 t O0 ARCTIC COMPANY Balance Sheets Dec 31, 2013 Dec. 31, 2012 Assets C...
1 answer
Suppose that X is a continuous random variable with probability distribution fx (x) = 0x6 18...
Suppose that X is a continuous random variable with probability distribution fx (x) = 0x6 18 (a) Find the probability distribution of the random variable Y = 15X10 fr (y) Edit ys for (b) Find the expected value of Y...
1 answer
Need a psychology research experiment that can be conducted in the college student that is in...
Need a psychology research experiment that can be conducted in the college student that is in the topic of hireability. 1x2 or 2x2 within subject preferably....
1 answer
Coronado Industries is contemplating the replacement of an old machine with a new one. The following...
Coronado Industries is contemplating the replacement of an old machine with a new one. The following information has been gathered: Old Machine New Machine Price $400000 $800000 Accumulated Depreciation 120000 -0- Remaining useful life 10 years -0- Useful life -0- 10 years Annual ...
1 answer
How do you evaluate #\frac { 4} { 5} + \frac { 3} { 10} + \frac { 3} { 5}#?
How do you evaluate #\frac { 4} { 5} + \frac { 3} { 10} + \frac { 3} { 5}#?...
1 answer
#7 (50 pts) Use an appropriate method to solve the given system 1 8 X'= +
#7 (50 pts) Use an appropriate method to solve the given system 1 8 X'= +...
1 answer
1. How does the poster portray the land of Iowa and Nebraska? 2. What incentives did...
1. How does the poster portray the land of Iowa and Nebraska? 2. What incentives did the Burlington & Missouri River Railroad Company offer? 3. Why would railroads want to encourage settlement?...
1 answer
Consider the following table of standard electrode potentials for a series of hypothetical reactions in aqueous...
Consider the following table of standard electrode potentials for a series of hypothetical reactions in aqueous solution: Reduction Half-Reaction A+ (aq) + e + A(8) B2+ (aq) + 2e → B(s) C18+ (aq) + e + C2+ (aq) D3+ (aq) + 3e + D(s) E° (V) 1.33 0.87 -0.12 -1.59 Part A Which substance is the ...
1 answer
Montgomery Company has developed the following flexible budget formulas for its four overhead items: Fixed Cost...
Montgomery Company has developed the following flexible budget formulas for its four overhead items: Fixed Cost $10,000 $ 1,500 Overhead item Maintenance Power Indirect labor cost Equipment lease Total Variable rate per direct labor hour $ 3.00 $ 0.30 $12.00 $_7,000 $18,500 $15.30 Montgomery normall...
1 answer
Was your recrystallized sample pure by TLC?  What were the potential impurities and how...
looking at TLC attached f(filtrate), p(purified crystals) a(starting aniline ) s(salicylaldehyde) , can somebody answer these questions for me ?? and calculate RF Was your recrystallized sample pure by TLC?  What were the potential impurities and how did you confirm their identities? What...
1 answer
I need help with Part e. I have already constructed the histogram using R and Rstudio (picture below). I am just confused about the empirical rule and locating the data points on the intervals. If a...
I need help with Part e. I have already constructed the histogram using R and Rstudio (picture below). I am just confused about the empirical rule and locating the data points on the intervals. If anyone could assist me, I'd appreciate it greatly! Thank you! e radon concentration (in pCi/liter)...
1 answer
Under the Microscope Dr. McKinney scheduled a craniotomy for biopsy of possible Creutzfeldt-Jakob disease (CJD). The...
Under the Microscope Dr. McKinney scheduled a craniotomy for biopsy of possible Creutzfeldt-Jakob disease (CJD). The patient has a history of having lived in the United Kingdom for 5 years prior to his return to the United States 10 years ago. His current mental status is declining and he is no long...
1 answer
Case study 2 Adam and his wife Brenda are organic farmers. They live in northern California...
Case study 2 Adam and his wife Brenda are organic farmers. They live in northern California and believe in a natural life style, free of pesticides, processed foods and they do not believe in vaccinations or un-natural medications. They have 4 healthy happy children. But lately their younger son Bil...
1 answer
Can someone explain this question for me? I understand I have to find an action potential,...
Can someone explain this question for me? I understand I have to find an action potential, Q value and use a Nernst equation, but I can not actually apply those into a question. Thanks Part A Calculate the cell potential of a concentration cell that has solid zinc and Zn 0.210 M for the cathode, and...