Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

modify the following program \"add two digits\" to add the least significant thr

ID: 3630767 • Letter: M

Question

modify the following program "add two digits" to add the least significant three digits (hundreds, tens and ones) rather than only two least significant


/* this program extracts and adds the two least significant digits in an integer. */

#include <stdio.h>

//Function Declarations
int addTwoDigits (int num);
int firstDigit (int num);
int secondDigit (int num);

int main (void)

{
// Local Declarations

int number;
int sum;
// Statements
printf(“ Enter and integer: “);
scanf(“%d”, &number);
sum = addTwoDigits (number);
printf (“ sum of last two digits is: %d, sum);

return 0;
}
/* Adds the first two digits of an integer. Pre num contains an integer Post returns sum of least significant digits
*/
{
// Local Declarations
int result;
// Statements
result = firstDigit (number) + secondDigit (number);
return result;
}
// addTwoDigits
/* extract least significant digit of an integer. Pre num contains an integer, post returns least significant digit
*/
int firstDigit (int num)
{
// Statements
return ( num % 10);
} // firstDigit
/* extract second least significant digit. Pre num is an integer. Post returns digit in 10’s position.
*/
int secondDigit (int num)
{
// Local Declarations
Int result;
// Statements
result = (num/10) % 10;
return result;
} // secondDigit


Explanation / Answer

please rate - thanks

/* this program extracts and adds the two least significant digits in an integer. */

#include <stdio.h>
//Function Declarations
int addTwoDigits (int num);
int firstDigit (int num);
int secondDigit (int num);
int thirdDigit (int num);
int main (void)

{
// Local Declarations

int number;
int sum;
// Statements
printf(" Enter and integer: ");
scanf("%d", &number);
sum = addTwoDigits (number);
printf (" sum of last three digits is: %d", sum);
return 0;
}
/* Adds the first two digits of an integer. Pre num contains an integer Post returns sum of least significant digits
*/
int addTwoDigits (int number)
{
// Local Declarations
int result;
// Statements
result = firstDigit (number) + secondDigit (number)+thirdDigit(number);
return result;
}
// addTwoDigits
/* extract least significant digit of an integer. Pre num contains an integer, post returns least significant digit
*/
int firstDigit (int num)
{
// Statements
return ( num % 10);
} // firstDigit
/* extract second least significant digit. Pre num is an integer. Post returns digit in 10’s position.
*/
int secondDigit (int num)
{
// Local Declarations
int result;
// Statements
result = (num/10) % 10;
return result;
} // secondDigit
int thirdDigit (int num)
{
// Statements
return ( num/100 % 10);
} // thirdDigit