Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help me in my C program.. (http://www.go4expert.com/forums/help-c-program-t22717/)

saphir3 14Jul2010 16:19

Help me in my C program..
 
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();
}

jimblumberg 14Jul2010 20:37

Re: Help me in my C program..
 
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

saphir3 15Jul2010 00:53

Re: Help me in my C program..
 
ya thanks.. got it..


All times are GMT +5.5. The time now is 17:36.