0

Hi guys, just wondering, how would i go about joining numbers together to form one integer..

example.. number 70 54 34

would end up being 705434..
thank u for your ideas...

5
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by dubeyprateek
0

Input is always three numbers of two digits or it can be 'n' numbers consisting any number of digits?

0

It can be any numbers and as many numbers and digits...
like 1 2 3 = 123
or 34 45 56 67 = 34455667

know what i mean ?

0

It can be any numbers and as many numbers and digits...
like 1 2 3 = 123
or 34 45 56 67 = 34455667

know what i mean ?

Well then you have to store it in a string. Because there's a limit of integers. Just accept the input as string and merge it.

0

Hi guys, just wondering, how would i go about joining numbers together to form one integer..

example.. number 70 54 34

would end up being 705434..
thank u for your ideas...

Hi I have the solution here... Just see is it your required one...
Plz reply me back.....

#include<stdio.h>
 int main()
{
int a[30],i=1,num,cnt=0,num1;
printf("Enter the numbers....\n");
printf("If dont want to continue enter 9999\n");
while(1)
{
scanf("%d",&num);
if(num==9999)
break;
a[i]=num;
i++;
cnt++;
}
num1=a[1];
for(i=2; i<=cnt; i++)
{
if(a[i]<=9)
{
num1=num1*10;
num1=num1+a[i];
}
else if(a[i]<=99 && a[i]>10)
{
num1=num1*100;
num1=num1+a[i];
}
else if(a[i]<=999 && a[i]>99)
{
num1=num1*1000;
num1=num1+a[i];
}
}
printf("%d",num1);
return 0;
}
0

Sorry, but that won't work:

It can be any numbers and as many numbers and digits...

your program only accepts numbers <=999:

else if(a[i]<=999 && a[i]>99)

I would go with strings too.

Regards Niek

0

It can be any numbers and as many numbers and digits...
like 1 2 3 = 123
or 34 45 56 67 = 34455667

know what i mean ?

What do u think about intiger overflows?
int can store maximum of 2,147,483,647.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.