Lab04_sample_for

# Lab04_sample_for - 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 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_for.cpp // Description: add up the numbers from 1 to n // Lab 04-1 // Author: Jaehyun Lim // Date: Sunday, July 1, 2007 #include <iostream> using namespace std; int main() { int number; int counter; int sum=0; cout << "Enter a number you want to add up to: " ; cin >> number; for (counter = 1; counter <= number; counter++) sum += counter; cout << "sum = " << sum << endl; return 0; } 2. Write a program that reads in numbers ten times from the user. Your program should then calculate and display their sum and average.

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

View Full Document
// File name: Lab04_02_for.cpp // Description: calculate sum and average of 10 inputs // Lab 04-2 // Author: Jaehyun Lim // Date: Sunday, July 1, 2007 #include <iostream> using namespace std; int main() { int count; double number; double sum=0; for (count = 1; count <= 10; count++) { cout << "Please enter a number: "
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

Lab04_sample_for - CMPSC 101 Introduction to Algorithmic...

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

View Full Document
Ask a homework question - tutors are online