Você está na página 1de 4

University of Management and Technology

School of Science and Technology


CS-141 Programming Fundamentals Fall 2011 Instructor-Jameel Ahmad ===================================================== Section C Homework Set #1(100 Points) Assigned: Thursday, Oct 27th, 2011 Due Date: Nov 02, 2011 (start of the class- during first 5 minutes) Penalty for: Late submission-------- (-50%) Cheating----------------zero Points =====================================================

Basic Arithmetic Statements

Question No-1 Answer the following using the above arithmetic and assignment operators (25 points) Part-A

1. Show how to increment an integer variable named count by 1. 2. Assign to basePay the sum of bonus and basePay. 3. Assign to bankBalance the difference found by subtracting withdrawal from bankBalance. 4. Find interestEarned by assigning it the product of balance multiplied by interestRate. 5. Use the "times equals" assignment operator in an arithmetic statement that multiplies amount by discountRate then stores the result in amount. 6. Modify the answer to the previous question to cause the result to be assigned to discountAmount (and not modify amount). 7. Show how to find milesPerGallon by dividing miles by gallons. 8. Write two statements to reduce the value referenced by the variable debt by half: once with a multiply operation and then with a divide.

9. Write a statement that will divide a variable named totalCents by dollarValue and assign the quotient to dollars. If totalCents is 151 and dollarValue is 100, what value would be assigned to dollars? 10. Divide totalCents by dollarValue and assign the remainder to a variable named change. If totalCents is 151 and dollarValue is 100, what value would be assigned to change?
Part-B

Short Questions: Please read the book if you dont know.(10 points) 1. 2. 3. 4. What is the line #include <stdio.h> at the top of a C source file for? What are some uses for comments? Why is indentation important? How carefully does the compiler pay attention to it? What are the largest and smallest values that can be reliably stored in a variable of type int? [ read the book] 5. What is the difference between the constants 7, '7', and "7"? [read the book] 6. What is the difference between the constants 123 and "123"? [read the book] 7. What is the function of the semicolon in a C statement? 8. Write a program to print the numbers from 1 to 10 and their squares:
1 2 3 ... 10 1 4 9 100

9. What do these loops print? ( 2 points) (Optional try if you can)


for(i = 0; i < 10; i = i + 2) printf("%d\n", i); for(i = 100; i >= 0; i = i - 7) printf("%d\n", i); for(i = 1; i <= 10; i = i + 1) printf("%d\n", i); for(i = 2; i < 100; i = i * 2) printf("%d\n", i);

10. Write a program to print this triangle: (Optional try if you can)
* ** *** **** ***** ****** ******* ******** ********* **********

Don't use ten printf statements; use two nested loops instead ( we have not studied yet loops) . You'll have to use braces around the body of the outer loop if it contains multiple statements:
for(i = 1; i <= 10; i = i + 1) { /* multiple statements */ /* can go in here */ }

11. What would this code print?


int x = 3; if(x) printf("yes\n"); else printf("no\n");

Writing Pseudo Code and Flow Chart (50 points)

Question 5 output.

Write pseudo code and a flow chart for a quadratic equation. Mention input and

ax 2 + bx + c = 0

Você também pode gostar