Saturday, August 18, 2018

RECURSION-5:NUMBER OF DIGITS

  • Problem Description

    Write a program to find the number of digits in a number using recursion.


    Input and Output Format:

    Input consists of a nonnegative integer.

    Refer sample input and output for formatting specifications.

    All text in bold corresponds to input and the rest corresponds to output.
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int a,b,count=0;
      scanf("%d",&a);
      b=a;
      while(a)
      {
        count++;
        a=a/10;
      }
      printf("The number of digits in %d is %d",b,count);

    return 0;
    }
  • Test Case 1

    Input (stdin)
    123
    
    
    Expected Output
    The number of digits in 123 is 3
  • Test Case 2

    Input (stdin)
    9
    
    
    Expected Output
    The number of digits in 9 is 1

No comments:

Post a Comment