ECS030 MT1 Practice S10 Key Camp

ECS030 MT1 Practice S10 Key Camp - ECS 30 Practice Midterm...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: ECS 30 Practice Midterm #1 Key Closed book, closed notes. Hanly Chapters 2-5. (10 points) You just printed something, and realize that it is a binary file that will print a bunch of garbage. What are the steps you take to cancel the print job? Use lpq to find the # of my print job and then use lprm job# to remove the job from the queue. (5 points) What UNIX command would you type to see a list of all of the files (including the hidden files) in directory hw1? ls -a hw1 (5 points) You just wrote and saved the file test2.c using vi. Now you want to make sure that only you can read and write it. What UNIX command would you type to make test.c only readable and writeable by you? chmod 600 test.c or chmod g-rw o-rw test.c (5 points) You want to move all of your C source files (ending in .c) and header files (ending in .h) from your hw1 subdirectory to your mid1 subdirectory. What UNIX command should you type? mv hw1/*.c hw1/*.h mid1 (5 points) You want to view the file test3.c a screen at a time. What UNIX command would you type? more test3.c (25 points) Given the following series of if statements, provide the outputs for each X. Note that more than one printf can be executed for each X. if (X > 20) printf(“First ”); else if(X < 5) printf(“Second “); else printf(“Third “); if(X == 20) printf(“Fourth “); else if(X < 19 || X > 25) printf(“Fifth “); if(X > 5 && X < 22) printf(“Sixth ”); a. (5 points) X = 0 __Second Fifth______ b. (5 points) X = 5 __Third Fifth _______ c. (5 points) X = 17 _Third Fifth Sixth_ d. (5 points) X = 20 _Third Fourth Sixth_ e. (5 points) X = 28 _First Fifth_________ (15 points) Write a for loop that will produce the same output as the following while loop. int x = 7; int x; while(x < 20) for(x = 10; x < 23; x = x + 3) { printf(“%d ”, x); x = x + 3; printf(“%d ”, x); } (20 points)Assuming that x is 11, y is 6, and z is 1 at the beginning of each statement what is the value of w: w = (x != y) -2 + 7 ____6___ w = x-- + y-- * ++z ____23__ w = x == y || x != y && z > x ____0___ w = !!(x * 4) + x % y ____6___ w = 7 * --y + !(y ==5) ____35__ (50 points) Write a complete, warning-free, C program that lists all of the common factors of two positive integers. The program will prompt the user for the two numbers, and then list on one line all the factors that the numbers have in common. A factor of a number divides into that number with a remainder of zero. The program will continue to ask the user for more pairs of numbers until the first number entered is zero. Your prompts and formats should match that shown. User input is in bold. Please enter two positive integers: 20 12 124 Please enter two positive integers: 60 120 1 2 3 4 5 6 10 12 15 20 30 60 Please enter two positive integers: 8 9 1 Please enter two positive integers: 0 230 Done. Pts 2 2 3 1 2 5 3 7 12 3 3 #include <stdio.h> int main() { int i, num, num1; do { printf("Please enter two positive integers: "); scanf("%d%d", &num, &num1); if(num > 0) { for(i = 1; i <= num; i++) if(num % i == 0 && num1 % i == 0) printf("%d ", i); printf("\n\n"); } } while(num != 0); printf("Done\n"); return 0; } 4 2 1 ...
View Full Document

This note was uploaded on 10/22/2010 for the course ECS 030 taught by Professor Staff during the Spring '08 term at UC Davis.

Ask a homework question - tutors are online