a program of substraction

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jenny

    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..W hy?Can you help me?
    Thanks a lot */

    #include<stdio. h>
    #include<stdlib .h>
    int remainder[21],remainder1[21],remainder2[21];


    int main()
    {
    long integer1,intege r2;
    int i,j,n;


    scanf("%ld%ld", &integer1,&inte ger2);

    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;remain der1[i] == 0;)
    i--;

    for(j=20;remain der1[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",rem ainder[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",rem ainder[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",rem ainder[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",rem ainder[j]);
    }/*end if*/

    return 0;
    }
  • Richard Heathfield

    #2
    Re: a program of substraction

    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

    Comment

    • Jenny

      #3
      Re: a program of substraction

      On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
      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(substr action 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.

      Comment

      • Jenny

        #4
        Re: a program of substraction

        On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
        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(substr action 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.

        Comment

        • Jenny

          #5
          Re: a program of substraction

          On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
          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(substr action 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.

          Comment

          • Jenny

            #6
            Re: a program of substraction

            On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
            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(substr action 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.

            Comment

            • Jenny

              #7
              Re: a program of substraction

              On 11ÔÂ1ÈÕ, ÏÂÎç4ʱ53·Ö, Richard Heathfield <r...@see.sig.i nvalidwrote:
              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(substr action 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.

              Comment

              • Richard Heathfield

                #8
                Re: a program of substraction

                Jenny said:

                <snip>
                Yeah,may be you're right.But today I've just finish another two
                programs(substr action 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

                Comment

                Working...