Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in Folio consisting of three files (a.c, a.h, main.c), write
1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in Folio consisting of three files (a.c, a.h, main.c), write a C program that consists of three files mysquare.h, mysquare.c and myMain.c. Below is the mysquare.h prototype
#include
#include
void generateNums(int *myarr, int len);
void squareNums(int *myarr, int len);
void printNums(int *myarr, int len);
- mysquare.h must contain only the function declarations (prototypes) listed above
- generateNums function should generate len random integers in the range 0~99 inclusive (use rand function in
) in the supplied array myarr. Its definition should be in mysquare.c. - squareNums function should square the len integers stored at myarr. Its definition should be in mysquare.c.
- printNums function should print the len integers stored at myarr on one line with suitable separators between them. Its definition should be in mysquare.c.
- Note that the caller of the above three functions should pass valid pointers myarr to them.
- In myMain.c you need to write your main function that calls the three functions in mysquare.h to generate N random integers in the range 0~99 inclusive and then print out the generated random numbers on one line and the squared N numbers on another line. Your program should get N(which represents the number of random integers you will generate) from the first command line argument (i.e. argv[1]) of this C program (you can use the atoi function; see example code LeapYear_cmdline.c). You need to decide where to store the N generated integers and where to store the N squared integers. Submit all the three code files. (37 pts)
- Submit a makefile to compile your program. Be aware of the possible file name issue regarding Folio complaint. See the last slide of 3_Pointers_Functions.pptx for details. Make sure you have tested that your makefile works. (3 pts)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started