You are on page 1of 3

Computer Systems and Programming EC-102

Assignment No 1
Due Date: 30th Oct, 2017
Assignment 2
Due Date: 11th March, 2014

Instructions:
 Please submit your assignment on/before the due date. No assignment
will be accepted after the due date.
 Assignment would be marked as zero without any explanation, if it is
found to be copied.

Question 1: Drivers are concerned with the mileage obtained by their


automobiles. One driver has kept track of several tankfuls of gasoline by
recording miles driven and gallons used for each tankful. Develop a C++
program that uses a while statement to input the miles driven and gallons used
for each tankful. The program should calculate and display the miles per gallon
obtained for each tankful and print the combined miles per gallon obtained for
all tankfuls up to this point.
Enter the miles used (-1 to quit): 287
Enter gallons: 13
MPG this tankful: 22.076923
Total MPG: 22.076923

Enter the miles used (-1 to quit): 200


Enter gallons: 10
MPG this tankful: 20.000000
Total MPG: 21.173913

Enter the miles used (-1 to quit): 120


Enter gallons: 5
MPG this tankful: 24.000000
Total MPG: 21.678571

Enter miles (-1 to quit): -1


Question 2: Calculate the value of  from the infinite series

pi = 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 ....

Print a table that shows the approximate value of  after each of the first 1,000 terms of this
series

The output might look like this;

term pi
1 4.00000000
2 2.66666667
3 3.46666667
4 2.89523810
5 3.33968254
6 2.97604618
7 3.28373848
8 3.01707182
9 3.25236593
10 3.04183962
...
990 3.14058255
991 3.14260174
992 3.14058459
993 3.14259970
994 3.14058662
995 3.14259768
996 3.14058864
997 3.14259566
998 3.14059065
999 3.14259365
1000 3.14059265

Question 3: Write a program that prints the prime numbers from 1 to 1000.

Question 4: Write a program to print Fibonacci series till the nth term, where n
is input by user : 0 1 1 2 3 5 8 13 24 .....

Question 5: Write a program that uses for statements to print the following
patterns separately, one below the other. Use for loops to generate the patterns.
All asterisks (*) should be printed by a single statement of the form cout << '*';.
[Hint: The last two patterns require that each line begin with an appropriate
number of blanks.
(a) (b) (c)
********** ********** *
********* ********* **
******** ******** ***
******* ******* ****
****** ****** *****
***** ***** ******
**** **** *******
*** *** ********
** ** *********
* * **********

You might also like