1 / 6

EXERCISES for ALGORITHMS WRITING

EXERCISES for ALGORITHMS WRITING. THE PROCEDURE: Define the problem in terms of Input, Process, Output Create a solution algorithm using pseudo-code. Problem No.1: Add three numbers A program is required to read 3 numbers, add them together and print their total.

preuss
Télécharger la présentation

EXERCISES for ALGORITHMS WRITING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EXERCISESforALGORITHMS WRITING

  2. THE PROCEDURE: • Define the problem in terms of Input, Process, Output • Create a solution algorithm using pseudo-code Problem No.1: Add three numbers A program is required to read 3 numbers, add them together and print their total. Inputs: num_1, num_2, num_3 Process: Addition Outputs: Display total of three numbers Algorithm: - Define num_1, num_2,num_3 and total - Read num_1 - Read num_2 - Read num_3

  3. - Add num_1, num_2 and num_3 into total - Display total Problem No.2: Find Average Temperature A program is required to prompt the terminal operator for the maximum and minimum temperature readings on a particular day, accept those readings as integers, then calculate & display to the screen the simple average temperature, calculated by: (maximum temperature + minimum temperature) / 2 Inputs: max_temp, min_temp Process: Add the max_temp & min_temp and then divide by 2 Outputs: Display avrg_temp

  4. Algorithm: - Initialize max_temp, min_temp, avrg_temp - Read max_temp - Read min_temp - Add max_temp & min_temp and then divide by 2 into avrg_temp - Display avrg_temp Problem No.3: Display Characters Construct an algorithm that will prompt user to input 3 chars, receive those 3 chars and display them to screen with a message, such as Hello ABC Inputs: chr_1, chr_2, chr_3 Outputs: Display “HELLO” with chr_1, Chr_2, Chr_3

  5. Algorithm: - Initialize chr_1, chr_2, chr_3 - Get chr_1 - Get chr_2 - Get chr_3 - Display chr_1, chr_2, chr_3 with a Hello message Problem No.4: Calculations A program is required to receive two integers from a terminal operator / user, process them and display to the screen their sum, difference, product and quotient Inputs: num_1, num_2 Process: Addition, Subtraction, Multiplication & Division Outputs: Display sum, diff, mul and div

  6. Algorithm: - Initialize num_1, num_2, sum, diff, mul, div - Get num_1 - Get num_2 - Add num_1 & num_2 into sum - Subtract num_1 from num_2 into diff - Multiply num_1 with num_2 into mul - Divide num_1 by num_2 into div - Display sum, diff, mul and div

More Related