Skip to main content
  1. Problem Solving Solutions/

Split an integer

·1 min
Problem Solving

We need to know the count of digits in the integer before we split it. Read here to know how to find the count of digits in logarithmic time.

C code to split an integer into two parts:

#include <stdio.h>
#include <math.h>
int main(void) {
 int n, divisor, len;
 printf("Enter a no.: ");
 scanf("%d", &n);
 if(n!=0){
     len=floor(log10(n))+1;
     divisor=pow(10, len/2);
     printf("1st part: %d\\n2nd part: %d", n/divisor, n%divisor);
 }
 return 0;
}