0% found this document useful (0 votes)
9 views1 page

Basic Programming Algorithm Examples

The document provides examples of algorithms for basic programming tasks, including grading, counting negative numbers, and finding the maximum number. Each example outlines the steps in a structured format, detailing variable declarations, conditions, and loops. The algorithms can be represented in both numbered and indented formats for clarity.

Uploaded by

aaron.butt16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Basic Programming Algorithm Examples

The document provides examples of algorithms for basic programming tasks, including grading, counting negative numbers, and finding the maximum number. Each example outlines the steps in a structured format, detailing variable declarations, conditions, and loops. The algorithms can be represented in both numbered and indented formats for clarity.

Uploaded by

aaron.butt16
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Example Algorithms

Example 1: Input a grade between 0 and 100. If the grade is greater than 50 display
pass, otherwise display fail.
1. Declare Variable to input a grade – grade
2. If grade >=50
a. Print to Screen “Pass”
3. Else if grade is less than 50
a. Print Fail

This could also be written without numbering and just indentation as follows:
Declare Variable to input a grade – grade
If grade >=50
Print to Screen “Pass”
Else if grade is less than 50
Print Fail

Example 2: Write a program to count all of the negative numbers entered by a user.
Enter -1 to exit.
1. Initialise variables
a. The number to read in, number
b. The counter variable, count
2. While the number is not equal to -1
a. Ask the user to enter a number
b. Increment the counter, count
3. When the number is equal to -1
a. Print the counter variable out to screen.
Example 3: Find the maximum number of a number of numbers read in.
1. Initialise variables
a. Define max to be a very low number or to the first number entered.
2. While the sentinel value is not reached
a. Keep reading in a number
b. If the number is greater than max
i. Set the max equal to the number

You might also like