10035 - Primary Arithmetic
Moderator: Board moderators
10035 help me plz
#include <iostream.h>
int main(void)
{int unsigned long a,b;
int s,z;
int unsigned long q[10],d[10];
while(cin>>a>>b)
{if((a==0)&&(b==0))return 0;
else{for(int i=1;i<=9;i++)
{q=0;d=0;}
for(int j=9;j>=1;j--)
{{q[j]=a%10;a=a/10;}{d[j]=b%10;b=b/10;}}
s=0;
for(int k=9;k>=1;k--)
{z=q[k]+d[k];
q[k-1]=q[k-1]+z/10;
if(z>=10)s++;
}
if(s!=0)cout<<s<<" "<<"carry operation."<<endl;
else cout<<"No carry operation."<<endl;}}
}
plz help[/b]
int main(void)
{int unsigned long a,b;
int s,z;
int unsigned long q[10],d[10];
while(cin>>a>>b)
{if((a==0)&&(b==0))return 0;
else{for(int i=1;i<=9;i++)
{q=0;d=0;}
for(int j=9;j>=1;j--)
{{q[j]=a%10;a=a/10;}{d[j]=b%10;b=b/10;}}
s=0;
for(int k=9;k>=1;k--)
{z=q[k]+d[k];
q[k-1]=q[k-1]+z/10;
if(z>=10)s++;
}
if(s!=0)cout<<s<<" "<<"carry operation."<<endl;
else cout<<"No carry operation."<<endl;}}
}

10035 WA
please tell me where is wrong
I have tried many times,but I didn't find wrong.
Thx
=============================================
#include <iostream>
using namespace std;
int test(int n1, int n2)
{
int times=0;
int r_n1,r_n2;
while(n1!=0 || n2!=0)
{
r_n1 = n1 % 10;
r_n2 = n2 % 10;
n1/=10;
n2/=10;
if(r_n1+r_n2 >=10)
{
++times;
n1+=1;
}
}
return times;
}
int main()
{
int num1,num2;
while(cin >> num1 >> num2)
{
if(num1==0 && num2==0)
break;
int times=test(num1,num2);
if(times==0)
cout << "No carry operation." << endl;
else if(times==1)
cout << "1 carry operation." << endl;
else
cout << times << " carry operations." << endl;
}
return 0;
}
I have tried many times,but I didn't find wrong.
Thx
=============================================
#include <iostream>
using namespace std;
int test(int n1, int n2)
{
int times=0;
int r_n1,r_n2;
while(n1!=0 || n2!=0)
{
r_n1 = n1 % 10;
r_n2 = n2 % 10;
n1/=10;
n2/=10;
if(r_n1+r_n2 >=10)
{
++times;
n1+=1;
}
}
return times;
}
int main()
{
int num1,num2;
while(cin >> num1 >> num2)
{
if(num1==0 && num2==0)
break;
int times=test(num1,num2);
if(times==0)
cout << "No carry operation." << endl;
else if(times==1)
cout << "1 carry operation." << endl;
else
cout << times << " carry operations." << endl;
}
return 0;
}
10035 Output Limit Exceeded
#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char num1[12],num2[12];
int a[12],b[12],ans[12] ,carry[12], size,i=0,k,m,n,o;
while(1)
{
gets(num1);
gets(num2);
if ( num1[0]==48&&num2[0]==48 )
break;
m=strlen(num1);
n=strlen(num2);
if(m>n)
size=m+1;
else
size=n+1;
for(i=0;i<size;i++)
{
a[i]=0;
b[i]=0;
ans[i]=0;
carry[i]=0;
}
i=m-1;
for(k=size-1;i>=0;k--)
{
a[k]=num1[i]-48;
i--;
}
i=n-1;
for(k=size-1;i>=0;k--)
{
b[k]=num2[i]-48;
i--;
}
o=0;
for(k=size-1;k>=0;k--)
{
if(( a[k]+b[k] )/10>=1)
{
o++;
}
carry[k-1]=( a[k]+b[k] )/10;
ans[k]=( a[k]+b[k] )%10+carry[k];
}
if(o>1)
printf("%d carry operations.\n",o);
else if(o==1)
printf("1 carry operation.\n");
else
printf("No carry operation.\n");
}
return 0;
}
Help me , please!
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char num1[12],num2[12];
int a[12],b[12],ans[12] ,carry[12], size,i=0,k,m,n,o;
while(1)
{
gets(num1);
gets(num2);
if ( num1[0]==48&&num2[0]==48 )
break;
m=strlen(num1);
n=strlen(num2);
if(m>n)
size=m+1;
else
size=n+1;
for(i=0;i<size;i++)
{
a[i]=0;
b[i]=0;
ans[i]=0;
carry[i]=0;
}
i=m-1;
for(k=size-1;i>=0;k--)
{
a[k]=num1[i]-48;
i--;
}
i=n-1;
for(k=size-1;i>=0;k--)
{
b[k]=num2[i]-48;
i--;
}
o=0;
for(k=size-1;k>=0;k--)
{
if(( a[k]+b[k] )/10>=1)
{
o++;
}
carry[k-1]=( a[k]+b[k] )/10;
ans[k]=( a[k]+b[k] )%10+carry[k];
}
if(o>1)
printf("%d carry operations.\n",o);
else if(o==1)
printf("1 carry operation.\n");
else
printf("No carry operation.\n");
}
return 0;
}
Help me , please!
Code: Select all
while(1)
{
gets(num1);
gets(num2);
Change it to:
Code: Select all
while ( gets(num1) != NULL )
gets(num2);
I'm sorry to say it didn't work.
But I have this:
if( num1[0]==48&&num2[0]==48 )
break;
if i followed what you say, it became "Compile Error".
if( num1[0]==48&&num2[0]==48 )
break;
if i followed what you say, it became "Compile Error".
-
- New poster
- Posts: 4
- Joined: Mon Jan 22, 2007 10:05 pm
- Location: Allahabad
- Contact:
plzzzzzzz help I m getting WA
code removed after got AC....
Happy Coding!!!
Pushpit Saxena
B-Tech@IIIT-A
Pushpit Saxena
B-Tech@IIIT-A
-
- New poster
- Posts: 10
- Joined: Sun Feb 11, 2007 1:01 pm
- Location: [CSE,BUET],DHAKA,BANGLADESH.
10035
// here is my code. whats the wrong??????????????????????
#include<stdio.h>
#include<string.h>
void main()
{
freopen("in.txt","r",stdin);
freopen("ot.txt","w",stdout);
char st1[10]={0},st2[10]={0};
while(scanf("%s%s",st1,st2)==2&&(strcmp(st1,"0")||strcmp(st2,"0")))
{
int carry=0,sum=0,total=0,flag=1;
int len1=strlen(st1),len2=strlen(st2);
if(len2>len1)
flag=0;
for(int k=len1-1;k>=0&&flag;k--)
{
len2--;
if(len2>=0)
{
sum=(st1[k]-48)+(st2[len2]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
else
{
sum=(st1[k]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
}
for(int p=len2-1;p>=0&&!flag;p--)
{
len1--;
if(len1>=0)
{
sum=(st2[p]-48)+(st1[len1]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
else
{
sum=(st2[p]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
}
if(total==0)
{
printf("No carry operation.\n");
}
else if(total==1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n",total);
}
}
#include<stdio.h>
#include<string.h>
void main()
{
freopen("in.txt","r",stdin);
freopen("ot.txt","w",stdout);
char st1[10]={0},st2[10]={0};
while(scanf("%s%s",st1,st2)==2&&(strcmp(st1,"0")||strcmp(st2,"0")))
{
int carry=0,sum=0,total=0,flag=1;
int len1=strlen(st1),len2=strlen(st2);
if(len2>len1)
flag=0;
for(int k=len1-1;k>=0&&flag;k--)
{
len2--;
if(len2>=0)
{
sum=(st1[k]-48)+(st2[len2]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
else
{
sum=(st1[k]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
}
for(int p=len2-1;p>=0&&!flag;p--)
{
len1--;
if(len1>=0)
{
sum=(st2[p]-48)+(st1[len1]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
else
{
sum=(st2[p]-48)+carry;
if(sum>=10)
{
carry=sum/10;
total++;
}
}
}
if(total==0)
{
printf("No carry operation.\n");
}
else if(total==1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n",total);
}
}
S. M. Arifuzzaman......
He dreamXtreme..................
But good4nothing................................
He dreamXtreme..................
But good4nothing................................
10035-Primary Arithmetic
I can't understand what is the wrong actually I did in this code. Please help me . My code is as follows:
Code: Select all
/* p10035 */
/* Primary Arithmetic */
#include<stdio.h>
#include<math.h>
void main()
{
int n1,n2,r1,r2,s,sum;
while(scanf("%d%d",&n1,&n2)!=EOF)
{
if(n1==0&&n2==0)
break;
s=0;
while((n1>0)||(n2>0))
{
r1=n1%10;
n1=n1/10;
r2=n2%10;
n2=n2/10;
sum=r1+r2;
if(sum>9)
s++;
}
if(s==0)
printf("No carry operation.\n");
else if(s==1)
printf("1 carry operation.\n");
else
printf("%d carry operations.\n",s);
}
}
// wrong ans