Docsity

Assignment 4 - Computer Science | CP SC 111, Assignments of Computer Science

Partial preview of the text

Download Assignment 4 - Computer Science | CP SC 111 and more Assignments Computer Science in PDF only on Docsity!

CpSe 111; Homework 4 Due: Tuesday, September 22™ at class time (scai Answer all questions on this sheet. 1) int vall=2: int yal2 = 0; 4) switch (vall) £ case 1: yal2 = yall; 22h yall: . u Sanu Ve lt? "case 2: __vald =2vall; Sime no “beck; a stack here val; ut fry tras case 3: val2=3¥vally oh cae 3. vall 4 default: c—_. And agar sna 5) val2 =5; no “becek we fl 3 : 4 , in he de fault cok . vall= 4 ? yval2= 5 ? 2) int x=1; int total=0; int y: x4 4. while (x <= 5) { sot ' y=xtx; zt s 6) total += y; soa xy 4 wh 30 2 s a sy : b Seals bee x= b Dy=_2¢ ?toal=-se? ry 3) int x; inty =0: x 4 2 oO & o— Ats7 3 6 ‘ — *tel int x; int y=0; for (x= i (X%3 = yteX if (x%3 ytex for (x=0, y } X= s Dy s “x<10: xtt) £ Name: n and email if necessary) e X<10; xt+) £ = 0) continue: = 0) break: 4 x o 86s | 2 2 4 3 1 ¢ 8) Complete the following code segment so thal il will print the powers of 2 starting al 2” up through the power read into the variable “power”. Define additional variables as needed. The output should look like (columns do not need to be aligned): 1 aN 0 1 2 3 tat als, cesult 215 int power. printf(“Enter the maxinmumn power”); scanf(“%d", &power): Sor Cady 9; abyez gouw, nbset) { peut Ce ed wd\n*, ads, recalt); result #22) 3 On net Mh sebly is | is, —————_ x 7 x4 ° T ° \ roe z 7 °? 3 te t £ © xs ¢ |