mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
formatting source-code for 9bc80876e8
This commit is contained in:
parent
9bc80876e8
commit
c563fc6694
@ -1,24 +1,24 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2020 @author iamnambiar
|
* Copyright 2020 @author iamnambiar
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
* \brief A C++ Program to find the Sum of Digits of input integer.
|
* \brief A C++ Program to find the Sum of Digits of input integer.
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to find the sum of the digits of an integer.
|
* Function to find the sum of the digits of an integer.
|
||||||
* @param num The integer.
|
* @param num The integer.
|
||||||
* @return Sum of the digits of the integer.
|
* @return Sum of the digits of the integer.
|
||||||
*
|
*
|
||||||
* \detail
|
* \detail
|
||||||
* First the algorithm check whether the num is negative or positive,
|
* First the algorithm check whether the num is negative or positive,
|
||||||
* if it is negative, then we neglect the negative sign.
|
* if it is negative, then we neglect the negative sign.
|
||||||
* Next, the algorithm extract the last digit of num by dividing by 10
|
* Next, the algorithm extract the last digit of num by dividing by 10
|
||||||
* and extracting the remainder and this is added to the sum.
|
* and extracting the remainder and this is added to the sum.
|
||||||
* The number is then divided by 10 to remove the last digit.
|
* The number is then divided by 10 to remove the last digit.
|
||||||
* This loop continues until num becomes 0.
|
* This loop continues until num becomes 0.
|
||||||
*/
|
*/
|
||||||
int sum_of_digits(int num) {
|
int sum_of_digits(int num) {
|
||||||
// If num is negative then negative sign is neglected.
|
// If num is negative then negative sign is neglected.
|
||||||
@ -52,7 +52,7 @@ void test2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for testing the sum_of_digits() with
|
* Function for testing the sum_of_digits() with
|
||||||
* all the test cases.
|
* all the test cases.
|
||||||
*/
|
*/
|
||||||
void test() {
|
void test() {
|
||||||
@ -64,7 +64,7 @@ void test() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Function
|
* Main Function
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
test();
|
test();
|
||||||
std::cout << "Success." << std::endl;
|
std::cout << "Success." << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user