Saturday, August 18, 2018

CONVERT ZERO TO FIVE

  • Problem Description

    Given a number your task is to complete the function convertFive which takes an integer n as argument and replaces all zeros in the number n with 5 .Your function should return the converted number .
  • CODING ARENA::
  • #include <stdio.h>
    int convert0To5Rec(int num)
    {
      if (num==0)
        return 0;
      int digit = num%10;
      if (digit == 0)
        digit = 5;
      return convert0To5Rec(num/10)*10+digit;
    }
    int convert0To5(int num)
    {
      if (num == 0)
        return 5;
      else return convert0To5Rec(num);
    }
    int main()
    {
      int num;
      scanf("%d",&num);
      printf("%d", convert0To5(num));
      return 0;
    }
  • Test Case 1

    Input (stdin)
    1004
    
    
    Expected Output
    1554
  • Test Case 2

    Input (stdin)
    5006
    
    
    Expected Output
    5556

1 comment: