Tuesday, January 29, 2008

C prog to find remainder of a number

A C prog to find remainder of a number without using division (/) or modulus (%)operator.

2 comments:

Sandeep Rao said...

I had made a program in 8085 uP coding....for division of number..and in the instruction set of 8085 operand to divide is missing....i vl crack it....for the time being its about utilising itoa() function from stdlib.h

Sandeep Rao said...

Here is the code :
#include"stdio.h"
void main()
{
int div,divid,lct,tmp_res,rem;

printf("Enter Divisor");
scanf("%d",&div);
prinf("Enter Dividend");
scanf("%d",&divid);

for (lct = 1;ilct<=divid;lct++)
{
tmp_res = lct * div;
if (tmp_res == divid)
{
rem = 0;
break;
}
else
{
if(tmp_res > divid)
{
rem = tmp_res - divid;
break;

}
}


}
printf("Quotient is %d, Reminder is %d",lct,rem);
}

I think i went overboard, it was very simple, Thank you very much Karuppusamy (my collegue)for waking me up...he has made me realised that my mind has caught junk.