Sie sind auf Seite 1von 3

CS113: Introduction to Programming Page 1

Department of Computing



CS113: Introduction to Programming
Class: BEE-6AB
Lab Task 3 - Variables, Data Types, Input, Output
Date: 24 September 2014
Instructor: Samin Khaliq












CS113: Introduction to Programming Page 2



Lab Task 3 - Variables, Data Types, Input, Output
Instructions
Complete the tasks below and save them on computer. Insert the solution/answer in this
document as directed below. You must show the execution of below tasks, along with your
completed Word document to get your work graded. You must also submit this Word document
on the LMS.

Deliverables
Compile a single Word document by filling in the solution/answer part and submit this Word file
on LMS.
This lab is graded. Min marks: 0. Max marks: 10.
Lab Tasks
Q1) Write a C program that computes the volume of a sphere with radius r, using the formula
v=4/3r
3
. Write the fraction 4/3 as 4.0/3.0. (Try writing it as 4/3. What happens?) Set the
value of radius r with assignment operator =. Define the value of as 3.14 to use in the
program. Hint: C doesnt have an exponentiation operator, so you will need to multiple r
thrice by itself to compute r
3
. Declare volume and radius as float. The output will be shown
using %f in printf as printf(Volume = %f, volume); Now change %f to %.2f (What
happens?)

Answer:
Solution: Code


Q2) Write a program that asks the user to enter a value for x and then displays the value of
the following polynomial 3x
5
+2x
4
-5x
3
-x
2
+7x-6. Use double data type for x. To calculate x
5

you will have to use pow(x,5).

Answer:
Solution: Code



CS113: Introduction to Programming Page 3


Q3) Write a program that asks the user to enter a US dollar amount and then shows how to
pay that amount using the smallest number of $20, $10, $5, and $1 bills. For example, see the
sample execution of program below:
Enter a dollar amount: 93
$20 bills: 4
$10 bills: 1
$5 bills: 0
$1 bills: 3
[Hint: be sure to use integer values throughout, not floating point numbers.]
First, develop the logic of program, then convert it to C code. Insert your C code below.

Answer:
Solution: Code

Das könnte Ihnen auch gefallen