Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with C void reverse Digits (int number) int numDigits (int number) The func

ID: 3791407 • Letter: H

Question

Help with C void reverse Digits (int number) int numDigits (int number) The function reverse Digits prints the digits of a number in reverse order. For example, for 12345 it prints 54321 and for 287 it prints 782. The function numDigits finds the number of digits in a number and returns it. For example, for 12345 it returns 5 and for 287 it returns 3. Use argc and argv in your program. You need to use atoi to convert the string parameter to an integer and include stdlib.h to use atoi. Sample output for this recitation is as follows fox01 rec 34567 76543 Output consists of two numbers written on separate lines. First output is for re- verse Digits and second output is for numDigits. Name your program recitations, c

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
void reverseDigit(int number){
   int reversedNumber,remainder;
   while(number != 0)
{
remainder = number%10;
reversedNumber = reversedNumber*10 + remainder;
number /= 10;
}  
printf("Reversed Number : %d ",reversedNumber);
}
int numDigit(int number){
   int count=0;
   while(number != 0)
{
number /= 10;
count++;
}  
   return count;
}
int main(int argc, char *argv[]){
   if ( argc != 2 ) /* argc should be 2 for correct execution */
   {
/* We print argv[0] assuming it is the program name */
printf( "please enter valid number of argument");
}else{
   reverseDigit(atoi(argv[1]));
       printf("Number Count : %d",numDigit(atoi(argv[1])));
}
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote