| |

Question: Write a program that computes an integer’s checksum. To compute the checksum, break the integer into its constituent digits and, working from right to left, doubling every second digit. If the product results in a number with two digits, treat those two digits independently. Then, sum all the digits for the final checksum. For example, 1496 has a checksum of 21. We compute this by first breaking 1496 into constituents and doubling the ever second digit. C++ please. – Free Chegg Question Answer

Write a program that computes an integer’s checksum. To compute the checksum, break the integer into its constituent digits and, working from right to left, doubling every second digit. If the product results in a number with two digits, treat those two digits independently. Then, sum all the digits for the final checksum. For example, 1496 has a checksum of 21. We compute this by first breaking 1496 into constituents and doubling the ever second digit. C++ please.

Transcribed text From Image: 

Expert Chegg Question Answer:

free chegg question answer
Smart Teacher From Answerie.com
Answer:

Answer


#include <bits/stdc++.h>

using namespace std;

int findCheckSum(int number){
  
//for getting the even digit position.
bool isEven = false;
int checkSum = 0;
  
while(number){
  
int digit = number%10; // get the digit.
number /= 10; // remove the last digit.
  
if(isEven){ // even position.
digit *= 2;
while(digit){
checkSum += (digit%10);
digit /= 10;
}
  
} else { // odd position
checkSum += digit;
}
isEven = isEven^true;
}
  
return checkSum;
  
}

int main() {
cout << findCheckSum(1496) << endl;
}


Free Chegg Question Answer

Leave a Reply

Your email address will not be published. Required fields are marked *