Try this.
Input:
Code: Select all
46457567568
3564567756756
2342343
0
Code: Select all
3611027666667
Moderator: Board moderators
Code: Select all
46457567568
3564567756756
2342343
0
Code: Select all
3611027666667
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i,add=0;
int j=0,carry,sum,max;
char num[102];
int res[105];
for(i=0;i<105;i++)
{
res[i]=0;
}
max=0;
while(scanf("%s",num)==1)
{
if(num[0]==48 && num[1]=='\0')
break;
sum=0;
carry=0;
j=0;
for(i=strlen(num)-1;i>=0;i--)
{
sum=res[j]+(num[i]-48)+carry;
if(sum>9)
{
res[j]=(sum%10) ;
carry=sum/10;
}
else
{
res[j]=sum ;
carry=0 ;
}
j++;
}
while(carry>0)
{
res[j]=(carry+res[j]);
carry=res[j]/10;
res[j]=res[j]%10;
j++;
}
if(max<j-1)
max=j-1;
}
for(i=max;i>=0;i--)
{
printf("%d",res[i]);
}
return 0;
}
Code: Select all
import java.util.*;
import java.math.*;
public class sum {
public static void main(String[] args) {
try{
BigInteger sum;
BigInteger zero=new BigInteger("0");
sum=zero;
Scanner in=new Scanner(System.in);
while(true){
BigInteger i;
i=in.nextBigInteger();
if(i.equals(zero))
break;
else
sum=sum.add(i);
}
System.out.println(sum);
}catch(Exception e){
}
}
}
Code: Select all
import java.util.*;
import java.math.*;
public class sum {
public static void main(String[] args)throws IOException {
try{
BigInteger sum;
BigInteger zero=new BigInteger("0");
sum=zero;
Scanner in=new Scanner(System.in);
while(true){
BigInteger i;
i=in.nextBigInteger();
if(i.equals(zero))
break;
else
sum=sum.add(i);
}
System.out.println(sum);
}catch(Exception e){
}
}
}