Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We write in C language: Project 2 generalised reverse for any number of digits: #include int main() { int n, reverse = 0; //input the
We write in C language:
Project 2 generalised reverse for any number of digits:
#include
int main() { int n, reverse = 0; //input the number printf("Enter a three-digit number : "); scanf("%d", &n); //till n becomes 0 repeat while (n != 0) { //find the last digit and add to already formed reverse reverse = reverse * 10 +n%10 ; //reduce number by 10 as last digit is alredy added to reverse n = n/10; } printf("The reversal is : %d ", reverse);
return 0; } output
// upc.c program:
3. Rewrite the program in Programming Project 2 so tha it prints the reversal of a three-digit number without using arithmetic to split the number into digits. Hint: See the upc.c pro- gram of Scction 4. Computes a Universal Product Code check digit / #include stdio.h> int main (void) upc.c int d, il, i2, , 4, i5, ji, j2, j3, j4, j5, first sum, second sum, total; printf ("Enter the first (single) digit:") scanf ( "% ld", &d) ; printf ("Enter first group of five digits:") scanf ("%ld%ld%ld% ld%ld", &1, &12, &13, &14, &i5); printf ("Enter second group of five digits: ") The missing check digits are S (lif) and 6 (Ocean Spray). Chapter 4 Expressions first _sum d i2 i4 j13 j5 second-sum i1 + i3 + i5 + j2 + j4; total 3 * firstsum + secondsum ; - - printf ("Check digit: %d ", 9 - ((total - 1) 10)); return 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started