1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Help me in my C program..

Discussion in 'C' started by saphir3, Jul 14, 2010.

  1. saphir3

    saphir3 New Member

    Joined:
    Jul 14, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I'm new to C. This program does division widout using division operator.
    But dis program works weird. It works for inputs like 9 3,8 3, etc.., but doesnt work for 8 2, and other higher inputs. Can ny1 plz help me wid dis?? :worried:

    # include <stdio.h>
    # include <conio.h>
    void main()
    {
    clrscr();
    int a,b,i;
    printf("2 numbers : ");
    scanf("%d %d",&a,&b);
    if (b==0)
    printf("invalid input");
    if(a>=b)
    {
    for(i=1;i<=a;i++)
    {
    a=a-b;
    if(a<b)
    {
    printf("remainder is %d and Quotient is %d",a,i);
    break;
    }
    }
    }
    else
    printf("remainder is %d and Quotient is 0",a);
    getch();
    }
     
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    Check out this section of your code:
    Code:
     for(i=1;i<=a;i++) 
    Both i and a are moving targets you probably need
    Code:
     for(i = 1; a < 0; i++) 
    Jim
     
  3. saphir3

    saphir3 New Member

    Joined:
    Jul 14, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    ya thanks.. got it..
     

Share This Page