Search This Blog

Makingcodesimple.

Simple solutions with explanation for the problems on competitive sites like hackerearth and many many more things like how to make your code faster, shorter and simple only at makingcodesimple.blogspot.com

Coursera's Algorithmic toolbox assignment solutions( Sum of Two Digits, Maximum Pairwise Product ) :

Problem 1: sum of two digits, solution: (in c++), ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder).

This code is simple. There's no need for any explanation.  

Problem 2: Maximum Pairwise Product

Guys , if you have any queries related to a question or need more explanation, comment down below!  

Post a Comment

Popular posts from this blog, hackerearth's basic programming solutions( seating arrangement, zoos, anagrams ) :, hackerearth's basic programming solutions( minimize cost, magical word, best index ) :.

Algorithms-UCSanDiego

Data structures and algorithms by ucsandiego, 1. sum of two digits.

https://en.wikipedia.org/wiki/Digit_sum

assignment 1 sum of two digits

Challenge: Sum of Two Digits

Solve the Sum of Two Digits Problem.

  • Coding exercise

Sum of Two Digits Problem

Compute the sum of two single digit numbers.

Input: Two single digit numbers.

Output: The sum of these numbers.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.

Assignments  »  Variable, Operator and Expression  »  Set 1  »  Solution 2

Write a program that prompts the user to enter two integers and display their sum on the screen.

Source Code

Enter the first integer: 10 Enter the second integer: 5 The sum of 10 and 5 is 15

queslers.com

Digit Sum Calculator

What is digit sum, how do i calculate the sum of digits of all numbers, sum of digits example, what is digit sum used for.

The digit sum calculator enables you to find the total sum of digits in any given set of numbers. You may view the results for each number separately or the entire set of numbers together. The outcome will be displayed as a table of the sum of digits. You also have the option to find the count of digits for the numbers and an example of the sum of digits to see how the calculator works!

We can obtain the sum of digits by adding the digits of a number by ignoring the place values. So, for example, if we have the number 567 , we can calculate the digit sum as 5 + 6 + 7 , which will give us 18 .

In this manner, we can find the total sum of the digits of any positive integer, using our digit sum calculator. The calculator also works for numbers of different orders of magnitude.

The sum of digits calculator considers the number of occurrences of each digit in the given numbers. It calculates the partial sum of each digit by multiplying the number of occurrences of the digit and the digit itself. It then adds these partial sums to find the total sum of digits.

You may also input a set of consecutive integers to find the sum of digits in all those numbers! It's also interesting to note that numbers occurring in everyday life tend to follow the Benford's law. We have a dedicated tool if you are curious, check out Benford's law calculator !

In order to find the sum of digits of the entire set of numbers, here's what you need to do:

  • Key in all the numbers into the digit sum calculator (up to 10 numbers).
  • Choose the Sum of digits option.
  • For the treatment of numbers, choose As a single group .
  • Voila! The sum of digits calculator will give you the total sum of all digits across all the numbers that you entered!

But if you're looking to calculate the total sum of the numbers and not just the digits, then you may want to use the addition calculator ! Alternatively, you may also try finding the digital root of the numbers!

Let's say you want to find the sum of digits in the following numbers:

1111177770999

After selecting the Sum of digits option, if you choose to treat each number separately , then you'll get the sum of digits as a table, as follows:

For the number 1111177770999:

For the number 5555555555:

For the number 0:

The No. of occurrences column also gives you the count of the number of digits. If you don't have any numbers handy, but you still want to try out this calculator, you may use our random number generator to get some numbers and input them here!

The most popular applications for the sum of digits lie in finding the divisibility of the given number. Here are a few rules that are based on the sum of digits:

Divisibility by 3 — If the sum of digits of a number is divisible by 3, then that number is also divisible by 3. For example, if we consider the number 123,453 , the sum of its digits is 18 , and we can further reduce the sum of digits of 18 to 9 . Since 9 is divisible by 3 , this means that 123,453 is also divisible by 3 ;

Divisibility by 9 — If the sum of digits of a number is divisible by 9, then that number is also divisible by 9. Looking at our earlier example, we can see that 123,453 is divisible by 9 too, since its sum of digits (18 and then subsequently 9) is divisible by 9!

Digit sums were also used in early computers as a means to check arithmetic or binary calculators .

What is the formula for sum of consecutive numbers?

To find the sum of N consecutive numbers, we'll use the formula N × (first number + last number) / 2 . So, for example, if we need to find the sum of numbers from 1 to 10 , we will have 10 × (1 + 10) / 2 , which will give us 55 .

What is the sum of digits from 1 to 100?

The sum of all digits of all numbers from 1 to 100 is 901 . This is obtained by adding digits 1 through 9 ten times for the units place, followed by adding digits 1 through 9 ten times again for the tens place, and then finally adding the digit 1 that's in the hundreds place of 100.

What is the sum of digits from 1 to 10?

The sum of all digits of all numbers from 1 to 10 is 46 . This result is obtained by adding digits 1 through 9 once for the single-digit numbers, followed by adding the digit 1 in the tens place of 10.

What is the sum of digits from 1 to 1000?

The sum of all digits of all numbers from 1 to 1000 is 13,501 . This result is obtained by doing the following:

  • Add digits 1 through 9 hundred times for the units place .
  • Add digits 1 through 9 hundred times again for the tens place .
  • Add digits 1 through 9 hundred times again for the hundreds place .
  • Finally, add the digit 1 that's in the thousands place of 1000.
  • Tada! We'll get the sum of digits of all integers from 1 to 1000 as 13,501 !
  • Least Common Multiple Calculator
  • Absolute Value Calculator
  • Interval Notation Calculator
  • Least Common Denominator Calculator
  • Null Space Calculator
  • Trig Identities Calculator
  • Partial Fraction Decomposition Calculator
  • Unit Rate Calculator
  • Exponential Function Calculator

Area of oblique triangle

Circle skirt, grams to cups.

  • Biology (101)
  • Chemistry (100)
  • Construction (147)
  • Conversion (295)
  • Ecology (30)
  • Everyday life (262)
  • Finance (571)
  • Health (440)
  • Physics (511)
  • Sports (106)
  • Statistics (184)
  • Other (183)
  • Discover Omni (40)
  • Interview Problems on Recursion
  • Practice Recursion
  • MCQs on Recursion
  • Recursion Tutorial
  • Recursive Function
  • Recursion vs Iteration
  • Types of Recursions
  • Tail Recursion
  • Josephus Problem
  • Tower of Hanoi
  • Check Palindrome

Program for Sum of the digits of a given number

  • Sum of digits of a given number to a given power
  • Find sum of digits in factorial of a number
  • Sum of digits equal to a given number in PL/SQL
  • Number with even sum of digits
  • Check if the sum of digits of N is palindrome
  • Check if the sum of digits of a number N divides it
  • Find the sum of digits of a number at even and odd places
  • Find M-th number whose repeated sum of digits of a number is N
  • C Program for Sum the digits of a given number
  • Java Program for Sum the digits of a given number
  • Python Program for Sum the digits of a given number
  • JavaScript Program for Sum of Digits of a Number
  • C# Program to Find Sum of Digits of a Number Using Recursion
  • Sum of digits of a number in PL/ SQL
  • Sum of the first and last digit of a number in PL/SQL
  • JavaScript Program for Sum of Digits of a Number using Recursion
  • PHP | Sum of digits of a number
  • JavaScript Program for Sum of Number Digits in a Linked List
  • Python | Sort list of numbers by sum of their digits

Given a number, find the sum of its digits.

Examples : 

Input: n = 687 Output: 21 Input: n = 12 Output: 3

Follow the below steps to solve the problem:

  • Get the number
  • Declare a variable to store the sum and set it to 0
  • Repeat the next two steps till the number is not 0
  • Get the rightmost digit of the number with help of the remainder ‘%’ operator by dividing it by 10 and adding it to the sum.
  • Divide the number by 10 with help of ‘/’ operator to remove the rightmost digit.
  • Print or return the sum

Below is the implementation of the above approach:

Time Complexity: O(log N) Auxiliary Space: O(1)

How to compute in a single line?

The below function has three lines instead of one line, but it calculates the sum in one line using for loop. It can be made one-line function if we pass the pointer to the sum. 

Sum of the digits of a given number using recursion:

  • Get the remainder and pass the next remaining digits
  • Divide the number by 10 with help of the ‘/’ operator to remove the rightmost digit.
  • Check the base case with n = 0

Time Complexity: O(log N) Auxiliary Space: O(log N)

Sum of the digits of a given number with input as string:

When the number of digits of that number exceeds 10 19 , we can’t take that number as an integer since the range of long long int doesn’t satisfy the given number. So take input as a string, run a loop from start to the length of the string and increase the sum with that character(in this case it is numeric)
  • Declare a variable sum equal to zero
  • Add the value of each character into the sum, by converting the character into it’s integer value

Time Complexity: O(N) Auxiliary Space: O(1)

Sum of the digits of a given number using tail recursion:

  • Add another variable “Val” to the function and initialize it to ( Val = 0 )
  • On every call to the function add the mod value (n%10) to the variable as “(n%10)+val” which is the last digit in n. Along with passing the variable n as n/10. 
  • So on the First call, it will have the last digit. As we are passing n/10 as n, It follows until n is reduced to a single digit. 
  • n<10 is the base case so When n < 10, then add the n to the variable as it is the last digit and return the val which will have the sum of digits

Please write comments if you find the above codes/algorithms incorrect, or find better ways to solve the same problem.

Please Login to comment...

Similar reads.

  • number-digits

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

Java assignment of Coursera Data Structures and Algorithms Specialization class

MarufHassan/coursera-data-structures-algorithms

Folders and files, repository files navigation, coursera: data structures and algorithms specialization.

Programming assignments for Data Structures and Algorithms Specialization .

About this Specialization

This specialization is a mix of theory and practice: you will learn algorithmic techniques for solving various computational problems and will implement about 100 algorithmic coding problems in a programming language of your choice.

The specialization contains two real-world projects: Big Networks and Genome Assembly. You will analyze both road networks and social networks and will learn how to compute the shortest route between New York and San Francisco (1000 times faster than the standard shortest path algorithms!) Afterwards, you will learn how to assemble genomes from millions of short fragments of DNA and how assembly algorithms fuel recent developments in personalized medicine.

COURSE 1: Algorithmic Toolbox

Programming Challenges

  • Sum of Two Digits
  • Maximum Pairwise Product

Algorithmic Warmup

  • Fibonacci Number
  • Last Digit of a Large Fibonacci Number
  • Greatest Common Divisor
  • Least Common Multiple
  • Fibonacci Number Again
  • Last Digit of the Sum of Fibonacci Numbers
  • Last Digit of the Sum of Fibonacci Numbers Again
  • Last Digit of the Sum of Squares of Fibonacci Numbers

Greedy Algorithms

  • Money Change
  • Maximum Value of the Loot
  • Maximum Advertisement Revenue
  • Collecting Signatures
  • Maximum Number of Prizes
  • Maximum Salary

Divide and Conquer

  • Binary Search
  • Majority Element
  • Improving Quick Sort
  • Number of Inversions
  • Organizing a Lottery
  • Closest Points

Dynamic Programming 1

  • Money Change Again
  • Primitive Calculator
  • Edit Distance
  • Longest Common Subsequence of Two Sequences
  • Longest Common Subsequence of Three Sequences

Dynamic Programming 2

  • Maximum Amount of Gold
  • Partitioning Souvenirs
  • Maximum Value of an Arithmetic Expression

COURSE 2: Data Structures

Basic Data Structures

  • Check brackets in the code
  • Compute tree height
  • Network packet processing simulation
  • Extending stack interface

Priority Queues and Disjoint Sets

  • Convert array into heap
  • Parallel processing
  • Merging tables

Hash Tables

  • Hashing with chains
  • Find pattern in text

Binary Search Trees

  • Binary tree traversals
  • Is it a binary search tree?
  • Is it a binary search tree? Hard version
  • Set with range sums

COURSE 3: Algorithms on Graphs

Decomposition of Graphs 1

  • Finding an Exit from a Maze
  • Adding Exits to a Maze

Decomposition of Graphs 2

  • Checking Consistency of CS Curriculum
  • Determining an Order of Courses
  • Checking Whether Any Intersection in a City is Reachable from Any Other

Paths in Graphs 1

  • Computing the Minimum Number of Flight Segments
  • Checking whether a Graph is Bipartite

Paths in Graphs 2

  • Computing the Minimum Cost of a Flight
  • Detecting Anomalies in Currency Exchange Rates
  • Exchanging Money Optimally

COURSE 4: Algorithms on Strings

Suffix Trees

  • Construct a Trie from a Collection of Patterns
  • Implement TrieMatching
  • Extend TrieMatching
  • Construct the Suffix Tree of a String
  • Find the Shortest Non-Shared Substring of Two Strings

Burrows-Wheeler Transform and Suffix Arrays

  • Construct the Burrows–Wheeler Transform of a String
  • Reconstruct a String from its Burrows–Wheeler Transform
  • Implement BetterBWMatching
  • Construct the Sufx Array of a String

This is only for discussion and communication. Please don't use this for submission of assignments.

IMAGES

  1. Sum

    assignment 1 sum of two digits

  2. Example 13

    assignment 1 sum of two digits

  3. Sum of two digits

    assignment 1 sum of two digits

  4. Sum of Digits Method

    assignment 1 sum of two digits

  5. Sum of the digits of a two-digit number is 9. Also, nine times

    assignment 1 sum of two digits

  6. Example 13

    assignment 1 sum of two digits

VIDEO

  1. digitSum program

  2. [Solved] BECC-104 Assignment 2023-24

  3. How to Solve LeetCode Two Sum

  4. Numerology 2024 DRIVER NUMBER 2

  5. #mathematical#maths#matheshorts#mathtrick#mathe #maths🧩

  6. TRICK 36 sum of the digits of a two-digit num 6. digits are reversed, num is increased by 36

COMMENTS

  1. coursera-algorithmic-toolbox/week1_programming_challenges/1_sum_of_two

    Saved searches Use saved searches to filter your results more quickly

  2. anoubhav/Coursera-Algorithmic-Toolbox

    The assignment solutions are in Python3. Disclaimer: The below solutions are for reference only. Please design and implement your own algorithms to pass the course. ... Last Digit of the Sum of Fibonacci Numbers; Last Digit of the Sum of Fibonacci Numbers Again; Last Digit of the Sum of Squares of Fibonacci Numbers; Week 3- Greedy Algorithms

  3. Coursera's Algorithmic toolbox assignment solutions( Sum of Two Digits

    Simple solutions for coursera's Algorithmic toolbox assignment questions: Sum of Two Digits, Maximum Pairwise Product by Making code simple! ... Problem 1: Sum of Two Digits Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) ...

  4. Sum of two digits

    Data Structures and Algorithms by UCSanDiego

  5. Challenge: Sum of Two Digits

    Sum of Two Digits Problem. Compute the sum of two single digit numbers. Input: Two single digit numbers. Output: The sum of these numbers. Level up your interview prep. Join Educative to access 70+ hands-on prep courses. Start Learning. Solve the Sum of Two Digits Problem.

  6. Python's sum (): The Pythonic Way to Sum Values

    Python's built-in function sum() is an efficient and Pythonic way to sum a list of numeric values. Adding several numbers together is a common intermediate step in many computations, so sum() is a pretty handy tool for a Python programmer.. As an additional and interesting use case, you can concatenate lists and tuples using sum(), which can be convenient when you need to flatten a list of ...

  7. Sum of Two Numbers

    Assignments » Variable, Operator and Expression » Set 1 » Solution 2 Write a program that prompts the user to enter two integers and display their sum on the screen. Source Code

  8. algebra precalculus

    0. Let the 2 -digit number be ¯ ab = 10a + b. If 9 is added to the number then both the digits become equal. This means that a = b, so the number plus 9 is 10a + a = 11a, which is always 0 mod 11 (divisible by 11 ). Therefore ¯ ab + 9 ≡ 0 mod 11 ⇒ ¯ ab ≡ 2 mod 11. But a + b ≡ 8 mod 11.

  9. Week 1

    I don't own any videos, uploaded on youtube to show it on my Coursera Clone Website,visit: freecoursera.github.io

  10. Queslers

    Queslers

  11. algorithm

    The complexity is proportional to the number of digits. After all, if there are 2,351 digits in the number, the while loop will iterate 2,351 times.. So the question boils down to, "how many digits are there in N, asymptotically?".A number with d digits is between 10^(d-1) inclusive and 10^d exclusive. In other words, let d be the number of digits in N, and we have the inequalities 10^(d-1 ...

  12. Algorithmic-Toolbox/week1_programming_challenges/1_sum_of_two_digits

    Saved searches Use saved searches to filter your results more quickly

  13. Python Program for Sum the digits of a given number

    Given a number represented as string str consisting of the digit 1 only i.e. 1, 11, 111, .... The task is to find the sum of digits of the square of the given number. Examples: Input: str = 11 Output: 4 112 = 121 1 + 2 + 1 = 4 Input: str = 1111 Output: 16 Naive approach: Find the square of the given number and then find the sum of its digits. Below

  14. Algorithmic-Toolbox-San-Diego/week1_programming_challenges/1_sum_of_two

    My Solutions of (Algorithmic-Toolbox ) Assignments from Coursera ( University of California San Diego ) With "Go In Depth" Part Which Contains More Details With Each of The Cour...

  15. python

    a × 10^ p + b × 10^ p-1 .. z × 10^ 0. so the sum of a number's digits is the sum of the coefficients of the terms. Based on this information, the sum of the digits can be computed like this: import math. def add_digits(n): # Assume n >= 0, else we should take abs(n) if 0 <= n < 10: return n.

  16. Digit Sum Calculator

    The sum of all digits of all numbers from 1 to 1000 is 13,501.This result is obtained by doing the following: Add digits 1 through 9 hundred times for the units place.; Add digits 1 through 9 hundred times again for the tens place.; Add digits 1 through 9 hundred times again for the hundreds place.; Finally, add the digit 1 that's in the thousands place of 1000.

  17. Program for Sum of the digits of a given number

    Follow the below steps to solve the problem: Get the number. Declare a variable to store the sum and set it to 0. Repeat the next two steps till the number is not 0. Get the rightmost digit of the number with help of the remainder '%' operator by dividing it by 10 and adding it to the sum. Divide the number by 10 with help of ...

  18. codecademy Practice Makes Perfect digit_sum

    Something like : def digit_sum(n): dig=0 # this is the result os the sum. number=str(n) #transform the number into string so we can iterate. for i in range(len(number)): dig=dig+int(number[i]) #transform the char to int. return dig #return the sum. I take the number (eg 123) and I transform it to a string so I can get the length of the string ...

  19. Solved COP1334C

    Step 1. COP1334C - Assignment #1 (Sum the digits in an integer) Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 932, the sum of all its digits is 14. Hint: Use the % operator to extract digits, and use the operator to remove the extracted digit.

  20. Programming Assignment Programming Assignment 1 Sum of Two Digits.png

    My files - OneDrive Other bookmarks Reading list coursera v Search in course Search Gabriel Tomagos Algorithmic Toolbox > Week 1 > Programming Assignment 1: Sum of Two Digits < Previous Next > Welcome Programming Assignment 1: Programming Challenges Programming Assignment: Programming Video: Solving the Sum of Two Digits Programming Challenge ...

  21. Sum Calculator

    A sum is the total amount calculated by addition of those numbers. The calculation performed is called addition or summation. A sum can be used to simply calculate a total amount such as, counting the number of people on each floor of a building then adding those numbers together to get the total amount of people in the building.

  22. Election Results 2024: NDA leading in 12 seats with less than 1% vote

    Election Results 2024: NDA won in 12 seats with less than 1% vote margin, in 16 seats with 1-2.5% A look at seats where the win margin is less than 2.5% Updated - June 06, 2024 07:44 pm IST

  23. Mega Millions

    After matching all six numbers drawn Tuesday night - the white balls 19, 37, 40, 63 and 69, plus the gold Mega Ball 17 - the single ticket takes the prize of $552 million ($260.2 million cash). The jackpot had been rolling since it was last won at $1.128 billion in New Jersey on March 26. Illinois was one of the founding members of Mega ...

  24. Text

    As of 06/08/2024 text has not been received for H.R.8671 - To amend the Homeland Security Act of 2002 to establish the Intelligence Rotational Assignment Program, and for other purposes. Bills are generally sent to the Library of Congress from GPO, the Government Publishing Office, a day or two after they are introduced on the floor of the ...

  25. Coursera-Algorithmic-Toolbox/assignment solutions/1.1 sum of digits.py

    / assignment solutions / 1.1 sum of digits.py. ... History. 3 lines (3 loc) · 53 Bytes master. Breadcrumbs. Coursera-Algorithmic-Toolbox / assignment solutions / 1.1 sum of digits.py. Top. File metadata and controls. Code. Blame. 3 lines (3 loc) · 53 Bytes. Raw. 1. 2. 3. #Python 3. a, b = input (). split print (int (a) + int (b)) Footer ...

  26. Coursera: Data Structures and Algorithms Specialization

    The specialization contains two real-world projects: Big Networks and Genome Assembly. You will analyze both road networks and social networks and will learn how to compute the shortest route between New York and San Francisco (1000 times faster than the standard shortest path algorithms!)