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

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

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...................:-))
-/QA/c/solution.c.- Sublime Text (UNREGISTERED) Project Preferences Help File Edit Selection Find View Goto Tools solution.c 1 2 #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; 4 5 6 } 8 9 11 14 15 16 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()); //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; 1/placing values in y_array for(int i=0;i<100;i++){ *(y_array+i)=y(*(x_array+i)); } 18 19 20 //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); 30 31 } Line 4, Column 58 Tab Size: 4 C
[email protected]: -/QA/C File Edit View Search Terminal Help
[email protected]:-/QA/c$ gcc solution.c
[email protected]:-/QA/c$ ./a.out
[email protected]:-/QA/c$ cat output.txt (6,59) (13,213) (4,33) (8,93) (2,15) (6,59) (14,243) (15,275) (2,15) (16,309) (10,135) (8,93) (17,345) (1,9) (6,59) (5, 45) (5,45) (11,159) (6,59) (13,213) (1,9) (4,33) (17,345) (6,59) (9,113) (12,185) (10,135) (11,15 9) (7,75) (10,135) (19,423) (12,185) (14,243) (2,15) (12,185) (15,275) (8,93) (5,45) (2,15) (9,113) (12,185) (11,159) (9,113) (9,113) (11,159) (14,243) (13,213) (8,93) (17,345) (10,135) (20,465) (17,345) (6,59) (16,3 09) (14,243) (14,243) (20,465) (3,23) (5,45) (6,59) (4,33) (3,23) (9,113) (10,135) (17,345) (20,465) (16,309 ) (4,33) (4,33) (17,345) (4,33) (8,93) (20,465) (4,33) (16,309) (10,135) (18,383) (20,465) (17,345) (14,243) (2,15) (17,345) (2,15) (7,75) (4,33) (7,75) (12, 185) (3,23) (9,113) (16,309) (20,465) (5, 45) (11,159) (9, 11 3) (14,243) (19,423) (8,93) (9,113) (14,243) (4,33)
[email protected]:-/QA/c$
.