{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab05_sample

# Lab05_sample - CMPSC 101 Introduction to Algorithmic...

This preview shows pages 1–3. Sign up to view the full content.

CMPSC 101 Introduction to Algorithmic Processes Summer 2007 LAB 5 – Loop Control List Headed by Size 1. Write a program that sums a sequence of integers. Assume that the first integer read with cin specifies the number of values remaining to be entered. Your program should read only one vale each time cin is executed. A typical input sequence might be 5 100 200 50 25 300 where the 5 indicates that the subsequent 5 value are to be summed // File name: Lab05_01.cpp // Description: sums a sequence of integers // Lab 05-1 // Author: Jaehyun Lim // Date: Thursday, July 5, 2007 #include <iostream> using namespace std; int main() { int number_of_values, input, sum=0; cout << "How many numbers do you want to enter? " << endl; cin >> number_of_values; cout << "Plese enter a number one at a time" << endl; for ( int counter=1; counter <= number_of_values; counter++) { cin >> input; sum += input; } cout << "Your total is " << sum << endl; return 0; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2. [text p.176] An approximate value of pi (π) can be calculated using the series given below: pi = 4*[1 – 1/3 + 1/5 – 1/7 + 1/9 … + ((-1) n )/(2n+1)] Write a C ++ program to calculate the approximate value of pi using this series. The
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}