Lab04_sample_while - CMPSC 101 Introduction to Algorithmic...

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

View Full Document Right Arrow Icon
CMPSC 101 Introduction to Algorithmic Processes Summer 2007 LAB 4 – while Loop 1. Write a program that will add up the numbers from 1 to n (n is a user input). // File name: Lab04_01.cpp // Description: add up the numbers from 1 to n // Lab 04-1 // Author: Jaehyun Lim // Date: Monday, June 25, 2007 #include <iostream> using namespace std; int main() { int counter; int sum=0; cout << "Enter a number you want to add up to: " ; cin >> counter; while (counter > 0) { sum += counter; counter--; } cout << "sum = " << sum << endl; return 0; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
Write a program that reads in numbers ten times from the user. Your program should then calculate and display their sum and average. // File name: Lab04_02.cpp // Description: calculate sum and average of 10 inputs // Lab 04-2 // Author: Jaehyun Lim // Date: Monday, June 25, 2007 #include <iostream> using namespace std; int main() { int count=10; double number; double sum=0; while (count > 0) { cout << "Please enter a number: " ; cin >> number; sum += number;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/14/2008 for the course CMPSC 101 taught by Professor Drobish,renee during the Summer '07 term at Pennsylvania State University, University Park.

Page1 / 7

Lab04_sample_while - CMPSC 101 Introduction to Algorithmic...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online