Respuesta :
Following are the C++ program to the given question:
#include <iostream>//header file
using namespace std;
int findCheckSum(int n)//defining a method findCheckSum that takes integer parameter
{
bool c = false;//defining bool variable
int S= 0,d;//defining integer variable
while(n)//defining while loop that seprates digits
{
d = n%10; // get the digit.
n=n/10; // remove the last digit.
if(c)//use if to check the even position value
{
d=d*2;//multiplying d with 2
while(d)//use if to check digit value
{
S=S+(d%10);//adding value
d=d/10;// remove the last digit.
}
}
else//defining else block
{
S=S+d;// checking the odd position
}
c= c^true;//holding bool value
}
return S;//return S
}
int main() //defining main method
{
cout << findCheckSum(1984);//calling method
}
Output:
22
Program Explanation:
- Including header file.
- Defining a method, "findCheckSum" that takes an integer parameter "n".
- Inside the method, a bool variable "c" and two integer variable "S, d" is declared that defines a while loop.
- Inside the loop, a conditional statement is defined that separates digits and adds them into the "S" variable, and returns its values.
- Outside the method, the main method is declared that calls the "findCheckSum" method, and print its value.
Learn more:
brainly.com/question/14788459