sample-final

sample-final - 1(a On a 32-bit machine a variable of type...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1. (a) On a 32-bit machine, a variable of type float is _____ bytes in size. (b) On a 32-bit machine, the following struct a is _____ bytes in size. struct a { int x; double y; }; (c) What is the value of NULL? (d) What C function concatenates one array of characters to the end of another array of characters? 2. The output of the following program is : M E CS Please fill in the blanks : #include<stdio.h> #include<stdlib.h> #include<string.h> struct a{ char as1[2]; char as2[2]; }; struct b{ char bs1; char bs2; char bs3[2]; }; int main(){ ____________ p1 = malloc(_______________); struct b p2; strcpy(p1->as1,strdup("ME")); strcpy(p1->as2,strdup("CS")); memcpy(&_________, p1, _______________); p2.bs3[2]='\0'; printf("%c\n", p2.bs1); printf("%c\n", p2.bs2); printf("%s\n", p2.bs3); return 0; } 3. The dot product of two vectors is computed by the following formula: sum {from i=1 to n} a_i * b_i For instance, if a = [1 2 3] b=[4 5 6]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
dotProduct(a,b) = 1*4+2*5+3*6 = 4+10+18 = 32 Complete the following code to compute a dot product */ double dotProduct(double *a, double *b, int n) { int i; double sum; sum = 0; for(i = 0; i < n; i++) sum += ______________; return sum; } /* In the numerical methods project, you wrote a program to compute the solution of a linear system Ax = b using the Gauss-Jordan method. There are many other methods for solving liner systems, and
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2012 for the course CS 240 taught by Professor Rego during the Spring '08 term at Purdue.

Page1 / 5

sample-final - 1(a On a 32-bit machine a variable of type...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online