COS120HomeWork_4 - spaces = number; //number of spaces to...

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

View Full Document Right Arrow Icon
a9fde5ad4c3611e917be69ff6f3a7b214e9021bc.doc COS120 Software Development Using C++ Homework 4 Iterative (Repetition, Loop) Statements Don’t forget: Paper record to be presented before the end of next class Tasks: Write a program to ask the user to input integer N and to display the following pyramid (output for N=5): 1 121 12321 1234321 123454321 Write a program to ask the user to input integer N and to display the following sequences (output for N=5): 2 4 6 8 3 6 9 12 4 8 12 16 5 10 15 20 Hint: Write appropriate number of comment lines. Prepare, P lease the paper record using the following template for the header page: COS120 Software Development Using C++ Student: Ivalina Petrova Homework Nmr 03 (Decisions) Tasks:
Background image of page 1

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

View Full DocumentRight Arrow Icon
a9fde5ad4c3611e917be69ff6f3a7b214e9021bc.doc Page 2 of 2 //Pyramid.cpp //The program displays a pyramid of numbers #include <iostream> using namespace std; int main( void ) { int number; //the number of rows printed cout << "Enter a number: " ; cin >> number; int
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: spaces = number; //number of spaces to be printed before a number for ( int i = 0; i <= number; i ++) { int print = i; //number to be printed for ( int j = 0; j < spaces; j ++) cout << " " ; //the number of numbers to be printed for each line where //i is the line number is i + (i + 1) = 2i + 1 for ( int k = 1; k < (2*i + 1)/2; k ++) //print numbers in ascending order cout << k; for ( int k = (2*i + 1)/2; k >= 1; k --) //print numbers in descending order cout << k; cout << endl; spaces --; } return 0; } //Sequence.cpp //The program displays a sequence of multiples of numbers //which are smaller than a number entered by the user #include <iostream> using namespace std; int main( void ) { int number; //the number of rows printed cout << "Enter a number: " ; cin >> number; for ( int i = 2; i <= number; i ++) { for ( int j = 1; j < number; j ++) cout << i*j << " " ; cout << endl; } return 0; }...
View Full Document

This note was uploaded on 04/24/2010 for the course COS 120 taught by Professor Bonev during the Fall '08 term at American University in Bulgaria.

Page1 / 2

COS120HomeWork_4 - spaces = number; //number of spaces to...

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

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