how to Split integer into two parts in c

Problem Statement:

Write a c program to accept n integers and split the integer into two equal parts and print the output.

Solution

 #include<stdio.h>

#include <stdlib.h>

#include<string.h>

int main()

{

long long int n,i,j,k,x,l,r;

scanf("%lld",&n);

char s[10000];

for(i=1;i<=n;i++)

{

    scanf("%s",s);

    x=strlen(s);

    r=0;

    l=0;

   for(j=0;j<x/2;j++)

   {

       r=r*10+(s[j]-48);

   }

   for(k=j;k<x;k++)

   {

       l=l*10+(s[k]-48);

   }

   printf("\n%d %d",r,l);

}

return 0;

}

Input

4

45 4578 4005 90

Output

4 5

45 78

40 5

9 0


Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post