0% found this document useful (0 votes)
20 views

Algorithms and Flowcharts To Solve Problems

Uploaded by

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

Algorithms and Flowcharts To Solve Problems

Uploaded by

kumarayush221104
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu

2. Algorithms and Flowcharts to Solve Problems

Examples:

(swaping)Exchanging Values Of Two Variables:

Algorithm: Using a third variable


Step 1 : Start
Step 2 : Read num1, num2
Step 3 : temp = num1
Step 4 : num1 = num2
Step 5 : num2 = temp
Step 6 : Print num1, num2
Step 7 : Stop

Algorithm: Without Using any Third Variable


Step 1 : Start
Step 2 : Read num1, num2
Step 3 : num1 = num1 + num2
Step 4 : num2 = num1 - num2
Step 5 : num1 = num1 - num2
Step 6 : Print num1, num2
Step 7 : Stop
© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com
Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu

Summation of a Set Of Numbers

Step1: Start
Step2: Initialize i=1 and sum=0
Step3: Read n
Step4: Repeat the i<=n
sum=sum+i
i=i+1
Step5: Print sum
Step6: Stop

Decimal Base To Binary Base


Conversion

Step1: Start
Step2: Define function ‘d_to_b()’
having parameter Named ‘num’
Step3: in the function Check for num>1
Step4: call the function and pass floor division
of the number ‘num’ as an argument
d_to_b(num//2)
Step5: Now Print num%2
#OutSide function
Step6: Read a number n
Step7: call function and pass the value of n
Step8: Stop

Algorithm find the largest among three numbers


Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a > b If a > c

© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com


Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu
Display a is the largest number.
Else
Display c is the largest number.
Else If b > c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

Algorithm to calculate the Simple Interest

Step 1: Start
Step 2: Read value of p, r, t
Step 3: Calculate Interest=(p * r * t)/100
Step 4: Print Interest
Step 5: Stop

Reversing Digits Of An
Integer

Step1: Start

© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com


Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu
Step2: Initialize reverse=0
Step3: Read Digit
Step4: Check whether digit>0 then go to
step 5 else goto step 4
Step5: reverse=reverse*10
Step6: reverse=reverse+digit%10
Step7: digit=digit/10
Step8: Goto Step 4
Step9: Display reverse
Step10: Stop

GCD (Greatest Common Divisor) Of


Two Numbers

Step1: Start
Step2: Read Two Number (num1 and num2)
Step3: Assign these number to a and b
(a=num1 and b=num2)
Step4: Repeat this Step until num2!=0
temp=num2
num2=num1%num2
num1=temp
Step5: Assign Value of num1 to variable
named gcd
Step6: Display Result
Step7: Stop

Factorial Computation

Step1: Start
Step2: Declare Variable n ,fact and i
Step3: initialize variable(fact=1 and i=1)
Step4: Read the value of N
© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com
Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu
Step5: Repeat these step until i==n
fact=fact*1
i=i+1
Step6: Display Fact
Step7: Stop

Test Whether A Number Is


Prime

Step1: Start
Step2: Declare variable n,i,flag
Step3: initialize variable
Flag=1,i=2
Step4: read a number n
Step5: Repeat the steps until i<(n/2)
If remainder of n/i equals 0
Flag=0, got to step 6
i=i+1
Step6: if flag==0 Display n is not
Prime
Step7: else Display n is prime
Step8: Stop

Fibonacci Sequence

© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com


Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu
Step1: Start
Step2: Declare Variable i,n,a,b,sum
Step3: initialize variable
a=0, b=1, sum=0
Step4: read a number n
Step5: Display a and b
Step6: Repeat the Steps until i<=n
sum=a+b
a=b
b=sum,i++
Step7: Display b
Step8: Stop

Evaluate ‘Sin X’ As Sum Of A Series

Step1: Start
Step2: take a number (x) in radians
Step3: take the value of n where n is a
number upto which we want to print
the sum of series
Step4: for first term
Sum=x, P=1, num=x, power=1
Step5: for next term
num=num*(-x2), power=power+2
p=p*(power-1)*power, next=num/p
Step6: The sum=sum+next
Step7: repeat the step 4 ,5 and 6 n-1 times
Step8: dislplay the value of sum
Step9: Stop

Find Largest Number In An list:

Step1: Start
© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com
Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu
Step2: initialize a empty list lst=[]
Step3: read how many number user enter in list
Step4: read each element(num) using a for loop
Step5: in the for loop append each number to
the list lst.append(num)
Step6: Display Largest element in array using
predefine function max(lst)
Step7: Stop

Disclaimer:

Some Content (Algorithm / Flowchart)Taken from Internet for


education purpose.

© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com


Youtube channel : New Ideas yt को Subscribe जरुर करे By Satyam Sahu

© Copyright All Rights Reserved. New ideas yt & http://www.sabdss.blogspot.com

You might also like