This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 gwﬂxlglV'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’tﬁfué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++);
printﬂ" %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*xz+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: ﬂoat 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)*(zx); 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 prodeclared as ﬂoat. 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
 Fall '05
 Fernando

Click to edit the document details