Please show all steps by commenting on code. Also, it needs to be written in C a
ID: 3630881 • Letter: P
Question
Please show all steps by commenting on code. Also, it needs to be written in C and compile with a linux based emacs system. Very new to coding so comments can be very basic to complex. I have a bi part of the problem done, but I'm not sure how to get the astericks in between and to matching the integer value inputed. Thank you for your help. Heres the question:Write a program reverse.c that prompts the user for a nonnegative integer and outputs a
sequence consisting of the entered integer, as many 's as the number of digits of the entered
integer, and the entered integer with its digits reversed. Here is a sample run:
(~)$ a.out
Enter an integer: 0
0*0
(~)$ a.out
Enter an integer: 123
123***321
(~)$ a.out
Enter an integer: 12000
12000*****00021
(~)$ a.out
Enter an integer: 021
21**12
(~)$ a.out
Enter an integer: 3024
3024****4203
(~)$
Heres what I have thus far, of which switches the integers:
#include <stdio.h>
int main(void)
{
int number, right_digit;
printf("Enter an integer: ") ;
scanf("%d", &number) ;
while (number != 0) {
right_digit = number % 10;
printf("%d", right_digit) ;
number = number / 10 ;
}
printf(" ") ;
return 0;
}
Explanation / Answer
#include int numdigits(int n) //this function finds out number of digits in an integer { int count = 1; /* bound to be at least one digit! */ while(n != 0) { n /= 10; ++count; } return count; } int main(void) { int number, right_digit; printf("Enter an integer: ") ; scanf("%d", &number) ; printf(" ") ; printf("%d",number); /*numdigits functions gives number of digits in the number. using that we can print those many number of * s using for loop as follows*/ for(int i=1;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.