Home » Find the Sum of Last Two Digits of an Integer Number

Find the Sum of Last Two Digits of an Integer Number

Learn about Find the Sum of Last Two Digits of an Integer Number in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Contents

Find the Sum of Last Two Digits of an Integer Number

The below program takes a number as input from the user. Then finds the sum of the last two digits and displays the result.

Program:

#include<stdio.h>

int addTwoDigits(int n);
int lastDigit(int n);
int secondLastDigit(int n);

int main()
{
   int number;

   printf("Enter an integer number: ");
   scanf("%d",&number);

   int sum = addTwoDigits(number);
   printf("Sum of last two digits is = %d",sum);

   return 0;
}

int addTwoDigits(int n)
{
   int result = lastDigit(n) + secondLastDigit(n);
   return result;
}

// function for finding last digit
int lastDigit(int n)
{
   return (n%10);
}

// function for finding second last digit
int secondLastDigit(int n)
{
   return ((n/10)%10);
}

Output:

Enter an integer number: 235
Sum of last two digits is = 8

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Find Square of a Number Using more than One Functions
Find Minimum & Maximum in Three Numbers by Function