Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
516 views

Algorithm, Pseudo Code and The Corresponding Flowchart

1. The algorithm calculates the sum of even numbers between 2 and n by initializing a sum variable to 0, iterating from 2 to n in increments of 2, adding each number to the running sum, and outputting the final sum. 2. The algorithm reads 100 numbers from the user, initializes a sum variable to 0, adds each input number to the running sum, and finally outputs the total sum of all 100 numbers. 3. The algorithm reads 3 numbers from the user, compares them to determine the largest, and outputs the largest of the 3 numbers. 4. The algorithm reads 100 numbers from the user, initializes a variable

Uploaded by

Arul Jothi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
516 views

Algorithm, Pseudo Code and The Corresponding Flowchart

1. The algorithm calculates the sum of even numbers between 2 and n by initializing a sum variable to 0, iterating from 2 to n in increments of 2, adding each number to the running sum, and outputting the final sum. 2. The algorithm reads 100 numbers from the user, initializes a sum variable to 0, adds each input number to the running sum, and finally outputs the total sum of all 100 numbers. 3. The algorithm reads 3 numbers from the user, compares them to determine the largest, and outputs the largest of the 3 numbers. 4. The algorithm reads 100 numbers from the user, initializes a variable

Uploaded by

Arul Jothi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Algorithm, pseudo code and the corresponding flowchart

1. Get two numbers from the user (dividend and divisor), testing to make sure that the divisor
number is not zero, and displaying their quotient.
Pseudocode: Flowchart:
Begin Step1: Start the program
Initialize dividend, divisor, quotient =0 Step2: Declare variables dividend, dividor,
OUTPUT “Enter values for dividend and quotient to 0
divisor” Step3: Print “ Enter values for dividend and
INPUT dividend, divisor divisor”
WHILE divisor = 0 Step4: Get values for dividend, divisor from
OUTPUT “Divisor must be non-zero” user
OUTPUT “Enter a value for divisor” Step5: Check if divisor=0, then
INPUT dividend, divisor Print “Divisor must be non-zer”
quotient = dividend / divisor Print “Enter a value for divisor”
OUTPUT quotient Get divisor
End Goto Step5
Else Goto Step6
Step6: Calculate,
quotient = dividend / divisor
Step7: Print quotient
Step8: Stop the program

2. Algorithm which generates even numbers between 1000 and 2000 and then prints them in the
standard output. It should also print total sum:
Pseudocode: Flowchart:
Begin Step1: Start the program
Initialize I ← 1000 and S ← 0 Step2: Declare variables I ← 1000, S ← 0
Write I Step3: Print I
WHILE (I <= 2000) Step4: WHILE( I <= 2000)
S←S+I S←S+I
I←I+2 I←I+2
Write S Print S
End Step4: Stop the program

3. Generate first 50 items of the Fibonacci series. The Fibonacci series are the numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...

By definition the first two numbers are:


Fibonacci(0) = 0
Fibonacci(1) = 1

The next number is always the sum of the previous two.


Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2)
Fibonacci(2) = 0 + 1 = 1
Fibonacci(3) = 1 + 1 = 2
Fibonacci(4) = 1 + 2 = 3
Fibonacci(5) = 2 + 3 = 5
Fibonacci(6) = 3 + 5 = 8
Fibonacci(7) = 5 + 8 = 13
Fibonacci(8) = 8 + 13 = 21
Fibonacci(9) = 13 + 21 = 34
Fibonacci(10) = 21 + 34 = 55
Fibonacci(11) = 34 + 55 = 89
Fibonacci(12) = 55 + 89 = 144
Fibonacci(13) = 89 + 144 = 233
Fibonacci(14) = 144 + 233 = 377
...
Pseudocode: Flowchart:
Begin Step1: Start the program
End
Step2: Declare variables i, a, b, n, show
Step3: Initialize the variables, a=0, b=1, and show =0
Step4: Print “Enter the number of terms of Fibonacci series to
be printed in variable n”
Step5: Get n
Step6: Print First two terms of series
Step7: While (i<=n)
show=a+b
a=b
b=show
i=i+1
print the value of show
Step8: Stop the program
4. Generates Prime number series between two given numbers ‘m’ and ‘n’, where m, n >
0.

Prime numbers are positive integers that can only be divided evenly by 1 or themselves. By
definition, negative integers, 0, and 1 are not considered prime numbers. The list of the first few
prime numbers looks like:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, ...

For example, 5 is a prime number because you can divide 5 by 1 evenly and divide 5 by 5
without a remainder, but if you divide 5 by any other integer, you get a remainder.
5/1 = 5
5/2 = 2 plus a remainder
5/3 = 1 plus a remainder
5/4 = 1 plus a remainder
5/5 = 1
5/6 = 0 plus a remainder
... = 0 plus a remainder

Now look at the number 4 which is not a prime.

4/1 = 4
4/2 = 2
4/3 = 1 plus a remainder
4/4 = 1
4/5 = 0 plus a remainder
... = 0 plus a remainder

The number 4 can be divided by 2 evenly, so it is not a prime.


Pseudocode: Flowchart:
Begin Step1: Start the program
Input N and M Step2:
While N is smaller than M
        Initialize I to 2
While I is smaller than N
               If  N is divisible by I
                         skip loop
               Increment I
               If  N is equal to I
                         Print N
               Increment N
End
Design algorithm, pseudo code and the corresponding flowchart for the
following:
1. Finding the sum of the numbers 2, 4, 6, 8, …, n
2. Read 100 numbers and then display the sum.
3. Read three numbers then display the largest.
4. Read 100 numbers then display the largest.
5. Calculate even numbers counts between 0 and 99

You might also like