thanks very much.
the code I have written:
my original intension is use a matrix ( the result[10][20] array in
the code ) to display all the things.
the first line is the quotient, the second line is "------------", and
so on.
but ,I soon found it's difficult to get the values of all the
individual bits of all the numbers.
for example,32344/16=2021, at first line,I must store how long is the
quotient, ( in this example,it's 4,and I must use a
variant to record it.)
I must store every bit of the number "2021", ( because I don't know its
length,so I must use a array.)
The worst, I won't know how long the dividend and the divisor will be.
and all the temporary values are request dividing to separate bit,too.
If the dividend is very big,and the divisor is small, the will be many
temporary numbers ,
so I found it's almost impossible .
<snip>
I didn't much bother to understand the bulk of the code, but If I may make
a small suggestion: It's better to approach this problem in steps.
Do the division /first/, and store the occasional number in an array of
integers.
When it's done, print the whole thing using /another/ function, and pass
it the array (and it's length) you filled in the first function.
By separating the division and the formatting, you're breaking the problem
up in smaller pieces. You'll be able to concentrate on getting the
division right, without turning it into a jumble. Functions Are A Good
Thing: A get_number_length() and a print_dashey_line(), would be quite
handy.
When formatting, you'll also have the advantage of having every number you
want to print ready. You'll be able to tell what the longest and shortest
numbers are, and format appropriately (printf ("%*.d", width, number)
might be useful here). You also don't have to store every digit of every
number, just store the numbers. Remember that you should check if you
reach the end of the array, and if you want extra cookies, stretch the
array (malloc(), realloc()).
I can't give you anything really concrete, because I don't know exactly
what you want and how you want it formatted. But at least it's something
to think about.
Blank lines good.
int result[10][20]={0},m,n; //the result matrix,m and n show the row
and the column index
There are two (or more) reasons C++-style comments are unwanted:
1) They've only been standard since C99
2) They can wrap on usenet, and cause problems, which is the case right
now.
Also, the 'm,n' at the end there is a bit hidden.
It's a good idea to group together related definitions, and seperate
unrelated ones. In this case:
int result[10][20] = {0};
int m, n;
In your case, it might already have caused some confusion, because you
define both m and n /AGAIN/ in main().
int stack[10]={0};//a simple "stack" .
int i=0;//a temporary variant
void divide(int dend,int dor)
{
}
/* dividend,divisor,minuend,subtrahend for short */
int dend,dor,mend,subend; /* temp variant */
int j,k,m,n;
/*
* temporary stack,used for store the individual bit of a number.
*/
Most of these identifiers are sort of bad. Why not name 't' 'temp_stack'
or some such? Are there better names for j, k, m and n?
printf("please input the dividend and the divisor.\n");
scanf("%d%d",&dend,&dor);
It's always a good idea to check scanf()'s return value. Someone might try
to input "Fourty and Two".
<snip jumble>