1. Homepage
  2. Exam
  3. [2019] ENG 1002 Programming (Matlab and C) - Semester 1 - Primary Examination - Q11 Memory & Data Representation in C

[2019] ENG 1002 Programming (Matlab and C) - Semester 1 - Primary Examination - Q11 Memory & Data Representation in C

This question has been solved
Engage in a Conversation

Question 11
Memory & Data Representation in C
CourseNana.COM

(a) Explain the types of values that each of the following C data types store, your answer must explain the advantage provided by each type: char, un- signed int, long int, float, double. [5 marks] CourseNana.COM

(b) Explain how C represents strings. [2 marks] CourseNana.COM

(c) Write C code that reads in two strings of up to 10 characters and prints out the longer of the two strings.
For example, the output of a run of the program might look like:
CourseNana.COM

Enter word 1: hello
Enter word 2: universe
The longer word is universe
CourseNana.COM

(d) The following C function takes two doubles: min and max. The function should update the passed values, placing the smallest of the two values in min and the largest in max. It does not currently work correctly. CourseNana.COM

void order(double min, double max) { CourseNana.COM

                if (max < min) { CourseNana.COM

                                double temp = min; CourseNana.COM

                                min = max; CourseNana.COM

                                max = temp; CourseNana.COM

               } CourseNana.COM

} CourseNana.COM

i. What will the following code output using the version of the order func- tion given above?
int main(void) { CourseNana.COM

                   double num1 = 6; CourseNana.COM

                   double num2 = 5; CourseNana.COM

                   order(num1, num2); CourseNana.COM

   printf("small %lf, large %lf \n", num1, num2); CourseNana.COM

   return 0; CourseNana.COM

} CourseNana.COM

ii. Write the correct C code for the function so that it behaves as expected. [5 marks] CourseNana.COM

iii. Correct the call in main to the order function. [2 marks] CourseNana.COM

  CourseNana.COM

(e) Write a C function, identity, that takes two arguments: rows, cols and creates a new rows x cols identity matrix. An identity matrix is a matrix with ones on the main diagonal and zeros elsewhere.  [13 marks] CourseNana.COM

[Total for Question 11: 33 marks ] CourseNana.COM

  CourseNana.COM

  CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
The University of Adelaide代写,ENG 1002代写,Programming (Matlab and C)代写,C代写,Matlab代写,The University of Adelaide代编,ENG 1002代编,Programming (Matlab and C)代编,C代编,Matlab代编,The University of Adelaide代考,ENG 1002代考,Programming (Matlab and C)代考,C代考,Matlab代考,The University of Adelaidehelp,ENG 1002help,Programming (Matlab and C)help,Chelp,Matlabhelp,The University of Adelaide作业代写,ENG 1002作业代写,Programming (Matlab and C)作业代写,C作业代写,Matlab作业代写,The University of Adelaide编程代写,ENG 1002编程代写,Programming (Matlab and C)编程代写,C编程代写,Matlab编程代写,The University of Adelaideprogramming help,ENG 1002programming help,Programming (Matlab and C)programming help,Cprogramming help,Matlabprogramming help,The University of Adelaideassignment help,ENG 1002assignment help,Programming (Matlab and C)assignment help,Cassignment help,Matlabassignment help,The University of Adelaidesolution,ENG 1002solution,Programming (Matlab and C)solution,Csolution,Matlabsolution,