Giter Site home page Giter Site logo

twu-program-exercise's Introduction

Introductory programming exercises

Triangle Exercises

Easiest exercise ever

Print one asterisk to the console.
Example:
*

Draw a horizontal line

Given a number n, print n asterisks on one line.
Example when n=8:
********

Draw a vertical line

Given a number n, print n lines, each with one asterisks
Example when n=3:

*
*
*

Draw a right triangle

Given a number n, print n lines, each with one more asterisk than the last (i.e. one on the first line, two on the second,etc.)
Example when n=3:

*
**
***

Diamond Exercises

Isosceles Triangle
Given a number n, print a centered triangle. Example for n=3:

  *
 ***
*****

Diamond

Given a number n, print a centered diamond. Example for n=3:

  *
 ***
*****
 ***
  *

Diamond with Name

Given a number n, print a centered diamond with your name in place of the middle line. Example for n=3:

  *
 ***
Bill
 ***
  *

FizzBuzz Exercise

FizzBuzz is a simple number game where you count, but say "Fizz" and/or "Buzz" instead of numbers adhering to certain rules.

Create a FizzBuzz() method that prints out the numbers 1 through 100.
Instead of numbers divisible by three print "Fizz".
Instead of numbers divisible by five print "Buzz".
Instead of numbers divisible by three and five print "FizzBuzz".

Sample Output:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

Prime Factors Exercise

Write a method generate(int n) that given an integer N will return a list of integers such that the numbers are the factors of N and are arranged in increasing numerical order.

For example, generate(1) should return an empty list and generate(30) should return the numbers: 2,3,5.

twu-program-exercise's People

Contributors

feixie-liam avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.