midtermsp01Sol - EGN 3210 Midterm Spring 2001 NAME éaw...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EGN 3210 Midterm Spring 2001 NAME éaw Z,’Qh§ SS# 1. Write a small program to input two numbers from the keyboard, max and incr and count from 0 to max in increments of incr. For example, if the user enters 10 and 3 then the output will be 0, 3, 6: 9. Use a for loop. #I‘wclde ”615.0.“ V019 \fvmfh C) 3 ”A X, WQX Mm 9(aMQC”'/& /)’l gwflxlglV'5/3) Qm (x 232))“ max x X‘f‘ihc’r) pix/Mew x), 3 2. Write a function to compute Z k= 1 + 2 + 3 + 4 + + (n— 1) + n. The input to the function IS the integer n and the output is the sum. For example if the input is 5 n(n +1) 2 then the output will be 15. Do Qt use 2 k = . Use a for loop. 16:! (”+3 6mm(ivi’i' W) 3. Write a segment of code to ask the user for 3 numbers in numerical order. Receive the numbers in variables a, b, c. If the numbers do not have this order a < b < c then repeat the process by asking the user to enter the numbers again. Repeat until a<b<e 50% I Far/$8) poi/Mg [Mama g u t @Ym’tfifuémiey 3 WMWLng lVI Q/9€Y\V‘ >/ 6(mQC” %& K) m 3 2’9 “eh/26>) @rquvewiw %wwi>evs m mam/J5) QWMVa za mgrajzb, w); ’é ~MV/eC 50b 11106)) 4. For each of the following code segments indicate what is the output. Assume all variables are declared. a. for (x = 0; x < 4; x++) printf(" %d, ",X); for(x=-5;x<=5;x=x+5) printf(" %d, ",X); for(x=0,y=0;x<=9;x=x+3) printf(" % d, n’y++); for(x=O;X<2;X++) for (y = 2; y > 0; Y") printf("%d %d\n",x,y); x =. 1; while ( x <= 10) { printf(" %d, ",X); x = x *2; } intx= 16; whi1e(x>4) { for (y= 0; y< 2; Y‘H') W 3,0,5 0mm . aY 0,9,69,112)! If M printf(" %d, %d ",x,y); x=x/2; } x = 0; while ( x < 7 ) { printf(" %d, ",X++); printf(" %d, ",x++); printfl" %d, ",x++); x = x + 2; } M, 0/4)! 0 / MAX—— 5. For each of the following code segments indicate what is the output. Assume the following declarations: int w = 0, x = 10, y = 20, z = 30; \/ X a. if(w==0&&x>16) printf ("True"); else printf("False"); 6" £53.— x / b. if(w*x==x*x||z+5>30) printf ("True"); .& printf("False"); TV M g / c. if (x = = 10) printf ("False"); <” l / 6 SC printf("True"); kg /5 6 else 6. For each of the following what is the variable assigned. Assume the following declarations: float x=10,y=20,z=30,a=0; a. a=x+z*x+y; - I ais 350 b. a=(x+y)/z; am I c. a=(x+y)*(z-x); ais 500 7. For the mathematical expression, write the equivalent c code to compute the expression and store the result in variable called result. Assume all of the variables used are pro-declared as float. Also assume the function sqrt(x) returns the square root of x. x+z_ f—*y(z+7) y met. It = (ma/y — §ZYT()M<(2+7>)/’ ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern