Convert zerotofive
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 convertFive(int n)
{
if(!n) return 0 ;
int curr=n%10 ;
n/=10 ;
if(!curr) curr=5 ;
return convertFive(n)*10+curr ;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d",convertFive(n));
return 0;
}
Test Case 1
Input (stdin)1004
Expected Output
1554
Test Case 2
Input (stdin)5006
Expected Output
5556
No comments:
Post a Comment