[go: up one dir, main page]

0% found this document useful (0 votes)
3K views2 pages

Algorithm For Sum of Digits and Fibonacci Series

The document describes an algorithm to calculate the sum of digits in a number. It involves: 1) Initializing a sum variable to 0 2) Repeatedly calculating the last digit of the number, adding it to the sum, and dividing the number by 10 until it reaches 0 3) Printing the final sum

Uploaded by

Kedar Kosuri
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)
3K views2 pages

Algorithm For Sum of Digits and Fibonacci Series

The document describes an algorithm to calculate the sum of digits in a number. It involves: 1) Initializing a sum variable to 0 2) Repeatedly calculating the last digit of the number, adding it to the sum, and dividing the number by 10 until it reaches 0 3) Printing the final sum

Uploaded by

Kedar Kosuri
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
You are on page 1/ 2

Algorithm for Sum of Digits in a Number.

1. Start
2. Read n
3. Consider the variables sum and count
3.1 Initialize sum=0
4. Check if n /= 0
4.1 If yes
4.2 Calculate count = n % 10
4.3 Calculate sum = sum + count
4.4 Determine value of n as n = n/10
4.5 If no
4.6 Go to step 6

5. Repeat the steps from 4 until n = 0


6. Print (sum)
7. Stop

Flowchart for Sum of Digits in a Number.

READ Initialize
STAR
n sum = 0
T

Count = n%10 If Yes If No


If n!=
Sum = sum + 0
Count

Determine n as
n = n/10 LOOP

Print sum

Stop
Algorithm for Fibonacci Series.
1. Start
2. Read n
3. Consider two variables a, b
3.1 Initialize values of a = 0 and b = 1
4. Print a, b
5. Let “c” is a variable initialized to 0
6. While n > 0
7. c = a + b
8. print c
9. a=b
10. b=c
11. n = n-1
12. Repeat steps from 6 to 11 until n==0
13. stop

Flowchart for Fibonacci series.

Let a=0
START Read n
b=0

If Yes If No
Print c c=a+b If n>0

a=b
n = n-1
b=c LOOP

Stop

You might also like