Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Learning Factorials and Trailing Zeros in Programming

Rating
-
Sold
-
Pages
1
Uploaded on
05-03-2023
Written in
2020/2021

This document discusses the concept of factorials and how to find the number of trailing zeros in them. It explains how twos and fives as a pair in a number result in the number of trailing zeros, and provides the formula n/5 + n/25 + n/125 + ... to find the number of fives in a factorial. The document also explains how to stop the process of finding the number of fives by adding 1 to all the numbers on the blackboard. Overall, this document emphasizes the importance of understanding factorials and trailing zeros in programming.

Show more Read less
Institution
Course

Content preview

Basic Math | Count Trailing Zeros in Factorial
of Number
Data Structures and Algorithms
Today we will be learning some important mathematical formulas and tricks that will help us in future
programming. Let us start with the factorial of a number. It is a straightforward process where we use an
integer to multiply n and, in every pass, we decrease n.

When we multiply a number by 10, it results in a trailing zero. In factorials, twos, and fives as a pair in a
number will result in the number of trailing zeros. For example, in the factorial of six (6!), there is only
one five and the number of twos is one, two, three, and four. So, at any point, the number of twos will
always be greater than the number of fives.

To find the number of fives in a factorial, we can use the formula: n/5 + n/25 + n/125 + ... (the list goes
on). For instance, let us say we want to find the number of trailing zeros in 10! We can use the formula
as follows:

10/5 + 10/25 = 2 + 0.4 = 2.4

Therefore, the number of trailing zeros in 10! is 2.

Now, you might be wondering how we can stop the process of finding the number of fives in a factorial.
We can stop it by adding 1 to all the numbers on the blackboard. For instance, if we have a variable
called "res," initially set to 0.5, "res" is the number that is just by itself (zero).

If "res" is less than 25, we must increase it by a multiple of 5 every time. But as soon as "res" becomes
more than n (the number we are finding the factorial of), we can break the loop.

To summarize, understanding the concept of factorials and how to find the number of trailing zeros is
crucial in programming. We can use the formula n/5 + n/25 + n/125 + ... to find the number of fives in a
factorial, and we can stop the process by adding 1 to all the numbers on the blackboard.

Written for

Course

Document information

Uploaded on
March 5, 2023
Number of pages
1
Written in
2020/2021
Type
SUMMARY

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
user111

Get to know the seller

Seller avatar
user111 University of Arizona College of Engineering
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions