Download presentation
Presentation is loading. Please wait.
Published byGinger Richards Modified over 9 years ago
1
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes we need to repeat some steps Examples
2
Computer science is a problem-solving discipline. Every solution should have a well-defined structure, such as listing the ingredients and steps for input, calculations and output.
3
Example problems How would you solve these problems? –Print the numbers from 1 to 10. –Searching for something. In this list (3, 2, 7, 5, 4) where is the number 5? Which room contains my umbrella? –Play Tic-Tac-Toe. Idea for solution (algorithm) is more important than typing code at the keyboard.
4
Computer program Sequence of instructions that machine carries out Nouns and verbs Structure: –Input, calculations, output –Auxiliary functions
5
Kinds of statements Get input Print output Assign value to variable If-else Loop
6
Algorithm Clear sequence of steps to arrive at a solution to a problem. Must specify: –Input, output, variables and operations used –The order in which the steps are taken Ideally, each step should perform one calculation: –Input or output of one value –One calculation, or decision to make –Calculations usually limited to basic math –Tedious details can be put off until later.
7
Examples Algorithm to add two numbers –Ask the user to enter 2 values –Obtain the input, and call the values a and b. –Set a new variable sum and set it to: sum = a + b. –Output sum. Calculate weekly wage. √ –Get hours and rate from the user. –Set the wage as follows: If (hours > 40), use overtime formula Otherwise, use regular formula –Output wage
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.