Question: 2. (70 points) Write a C program that asks the user to enter a positive integer (the integer could be of any number of digits
2. (70 points) Write a C program that asks the user to enter a positive integer (the integer could be of any number of digits in the range of the integer type) and replace each digit by the sum of that digit plus 6 modulus 10. The program then should swap the first digit with the last digit before it displays the output.
A sample input/output:
Enter the number of digits of the number: 5 Enter the number: 92828 Output: 48485
1) Name your program replace2.c.
2) The user will enter the total number of digits before entering the number.
3) You can use format specifier "%1d" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num.
4) As part of the solution, write and call the function replace() with the following prototype. The replace() function assumes that the digits are stored in the array a and computes the replaced digits and store them in the array b. c represents the size of the arrays.
void replace(int *a, int *b, int n);
The replace() function should use pointer arithmetic not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.
5) As part of the solution, write and call the function swap() with the following prototype.
void swap(int *p, int *q);
When passed the addresses of two variables, the swap() function should exchange the values of the variables: swap(&i, &j); /* exchange values of i and j */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
