473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

a program of substraction

/*I made this program to do substraction between two integers
whose digits are beyond the limit of a long int on my system
but the program can only execute within 10 digits.What's more only
under the condition "i>j"and "i==j"does the program work
successfully..Why?Can you help me?
Thanks a lot */

#include<stdio.h>
#include<stdlib.h>
int remainder[21],remainder1[21],remainder2[21];
int main()
{
long integer1,integer2;
int i,j,n;
scanf("%ld%ld",&integer1,&integer2);

for(n=1;n<=20;n++){
remainder1[n] = integer1 % 10;
integer1 = (integer1 - remainder1[n]) / 10;
remainder2[n] = integer2 % 10;
integer2 = (integer2 - remainder2[n]) / 10;
}

for(i=20;remainder1[i] == 0;)
i--;

for(j=20;remainder1[j] == 0;)
j--;

if(i>j){
for(n=0;n<=20;n++){
if(remainder1[n]<remainder2[n]){
remainder1[n]+=10;
remainder1[n+1]-=1;
}/*end if*/
remainder[n]=remainder1[n]-remainder2[n];
}/*end for*/

for(;i>=1;i--)
printf("%d",remainder[i]);
}/*end if*/

if(i==j){
for(;remainder1[i]==remainder2[i];)
i--;
if(remainder1[i]>remainder2[i]){
for(n=0;n<=20;n++){
if(remainder1[n]<remainder2[n]){
remainder1[n]+=10;
remainder1[n+1]-=1;
}/*end if*/
remainder[n]=remainder1[n]-remainder2[n];
}/*end for*/
for(;remainder[i]==0;)
i--;

for(;i>=1;i--)
printf("%d",remainder[i]);
}/*end if*/

if(remainder2[i]>remainder1[i]){
for(n=0;n<=20;n++){
if(remainder2[n]<remainder1[n]){
remainder2[n]+=10;
remainder2[n+1]-=1;
}/*end if*/
remainder[n]=remainder2[n]-remainder1[n];
}/*end for*/
for(;remainder[i]==0;)
i--;

printf("-");

for(;i>=1;i--)
printf("%d",remainder[i]);
}/*end if*/
}/*end if*/
if(j>i){
for(n=0;n<=20;n++){
if(remainder2[n]<remainder1[n]){
remainder2[n]+=10;
remainder2[n+1]-=1;
}/*end if*/
remainder[n]=remainder2[n]-remainder1[n];
}/*end for*/

for(;j>=1;j--)
printf("%d",remainder[j]);
}/*end if*/

return 0;
}
Nov 1 '08 #1
7 2223
Jenny said:
/*I made this program to do substraction between two integers
Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 1 '08 #2
On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.invalidwrote:
Jenny said:
/*I made this program to do substraction between two integers

Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
I need your help.
Nov 1 '08 #3
On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.invalidwrote:
Jenny said:
/*I made this program to do substraction between two integers

Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
I need your help.
Nov 1 '08 #4
On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.invalidwrote:
Jenny said:
/*I made this program to do substraction between two integers

Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
I need your help.
Nov 1 '08 #5
On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.invalidwrote:
Jenny said:
/*I made this program to do substraction between two integers

Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
I need your help.
Nov 1 '08 #6
On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.invalidwrote:
Jenny said:
/*I made this program to do substraction between two integers

Yeah, it has the same problem as your addition program.

See my reply re your addition question in acllcc++.

If you must post the same article to more than one group (rarely a good
idea), cross-post rather than multi-post.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
I need your help.
Nov 1 '08 #7
Jenny said:

<snip>
Yeah,may be you're right.But today I've just finish another two
programs(substraction and mutiplication),again and again I almost met
the same problem,
Yes. Your problem is obvious. What is not obvious is why you think that
making yourself unpopular with helpers is a useful strategy.

If you cross-post an article, it will still go to each newsgroup that you
want it to, but any individual reader (with a good news client) will only
get to see it once. When you multi-post, you are showing them the same
article multiple times. That is not going to endear you to people.
so I make multi-post.I think in this way i will have
a more clear idea of my mistakes.next time I won't go wrong again.
It isn't clear that you understand what is meant by "multi-posting", nor
why you think more irritation + less help = clearer idea.
I need your help.
If you need people's help, it's best to follow the conventions that are
least likely to give them cause not to help you.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Nov 1 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: sonic | last post by:
Hello, What is the correct way of performing this substraction in JS. var a = '29.33'; ( or 29.33 ) var b = '0.01'; ( or 0.01 ) var result = a - b; ( result = 29.319999999999996; )
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
1
by: Jenny | last post by:
/*I made this program to do substraction between two integers whose digits are beyond the limit of a long int on my system but the program can only execute within 10 digits.What's more only under...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.