Prabakar 77 Posting Whiz

Well, I ain't know this for sure, but please do try to replace getch() with scanf() or getchar()

Prabakar 77 Posting Whiz

I don't have a turbo c compiler at home, though I am forced to use it in college.

Is it the case with you too? If not, the 32 bit world offers better ways to do everything.

I had a glance of your code & I want to say something

1) Formate your code
2) Use Code Tags
3)

while(!kbhit()){
if (kbhit())
c=getch();
}

When you want to wait indefinitely, just c= getch() will be enough.

4) calling scene() in call() & call() in scene() Does the program end? That may be the reason for the flashing.

Hope it helps:)

Lastly, Could you please state the problem.

EDIT:

There is something more that I want to say.

Console output did not work for me in graphics mode. perhaps console input too does not work & it may also be a reason for the flashing(not sure) I shall test it in college tomorrow.

Prabakar 77 Posting Whiz

you hate recusion? Thats bad

When i first learned it. It was fun.

Recursion makes things simple for you. Programs like towers of honai, Infix to postfix, tree traversals are very much easy when we use recursion.

The problem with me is that I DONT know where to use it & where not to. thats why I choose the loops. But no way I would hate it, for my inability.

So, try to love it:)

Prabakar 77 Posting Whiz

curiously, Is it a must to use recursion for this problem?
I ask because, my poor usage of recursion makes me run out of stack memory many times, so i tend to avoid it completely.

Prabakar 77 Posting Whiz

ya its right.

power == 1 will be handled by
return base * pow( base, power-1 );
so 2nd if though right, its not needed

I've edited the previous post have a look at it

Prabakar 77 Posting Whiz

one more
if ( power % 2 != 0) & not power % 2 == 0

The code is working good for positive numbers as I thought.

int pow ( int base, int power )
{
     if ( power )                                                          // if not 0
     {
          if ( power % 2 ) // if odd then 5^7 say == 5*5^6
              return base * pow( base, power-1 ) ;
          return pow ( base * base, power/2 ); // else if even, then the shortcut your book said
     }
     return 1 ;   // if 0 then return 1 since any^0 = 1 ;
}

Now, have I made myself clear?

Prabakar 77 Posting Whiz

if ( power > 0 ) is what i meant not >= 0. Now that you said it, I'll get rid of my laziness & check my code I shall reply soon if there is a change.

Prabakar 77 Posting Whiz
#include <cstdlib>
#include <iostream>

using namespace std;

int main( )
{
    int pow ( int, int ) ;
    return EXIT_SUCCESS;
}

int pow ( int base, int power )
{
     if ( power )
     {
          if ( power % 2 ) return base * pow( base, power-1 ) ;
          return pow ( base * base, power/2 );
     }
     return 1 ;
}

This is a code I came up with. I must admit that I did not test it. I dont know if it will work with all cases ( 5 ^ -2 ). I am confident though that it will work with positive numbers unless ofcourse you give big values to crash the program. Hope you can build on this code to deal with all cases:)

Prabakar 77 Posting Whiz

Dequeue is simple. since it is a queue you need head & tail. I don't know what you are trying to do with new_num. So I'll leave it. And it seems you want to delete all nodes in the queue with the dequeue() Actually dequeue deletes just the first node. so a code like this would do.

bool dequeue()
{
      // check if empty
   temp = head ;
   if ( head == tail ) 
     head = tail = NULL ;
   else 
     head = head-> link ;
   delete temp ;
}

Hope it helps:)

Prabakar 77 Posting Whiz

I read few lines of code. And so far I have found some silly mistakes

1) if (! argc > 1) will always fail because ! has higher priority than >

this priority stuff confuses me a lot so I always use () to aviod the confusion

2) the string file was never assigned a value.

Besides this need you open the same file twice ( once in main & once in sub_fn )

Prabakar 77 Posting Whiz

I posted an Identical thread in c fourum & but mine was faster though. It takes a few minutes to find a combination. & then to improve the performance, I'll give the same link I recived Warnsdorff's Algorithm

Prabakar 77 Posting Whiz

If you use dynamic allocation because I told you, then I am sorry, because I ment to use dynamic allocation for the random array. Since, every time you allocate a cluster of memory from the heap and is bound to be different form the previous one.

Prabakar 77 Posting Whiz

test ( 5, 5, 7.3, 'z' ) will work.
And, What is your question?
>>I need a statement for the function test

what statements?

Prabakar 77 Posting Whiz

I agree with that, printed to stdout & scaning from stdin. your code is wrong & I guess, you have not yet learned pointers. So, I would use arrays hear

declare char c[30] ;
in the loop, put c[i++] = rem ;
then in another while loop
while ( i ) putchar ( c ;

Prabakar 77 Posting Whiz

I am new to forums too, as far as I can see, You can edit you post right after you post a message.

Prabakar 77 Posting Whiz

Using String would be better.

Prabakar 77 Posting Whiz

in decimal to binary, calcuation is ok. you are priinting binary number in reverse order

Prabakar 77 Posting Whiz

Well, if dealing with 2-d is your problem, try this. len n = r * c of the matrix.

use buble sorting, on matrix[0][0] to matrix[0][n-1]. It will sort, the matrix, left to right & top to bottom

And also, in the code, you use, NO_OF_ROWS as a matrix, as a function & as an integer. What is this?

Prabakar 77 Posting Whiz

I dont like to use recursion, unless it is very much necessary. If i were to calcualte GCD between 2 numbers, I would do it somthing like this.

#define min(a, b) (a)<(b)?(a):(b)
int main ( )
{
    int a, b, i, c, d, gcd = 1, lcm ;
    cin >> a >> b ;
    c = a ; d = b ;
    for ( i = min(a, b) ; i > 1 ; i-- )
         if ( a % i == 0 && b % i == 0 )
         {
              gcd = gcd * i ;
              a = a / i ;
              b = b / i ;
              i = min ( i, min ( a, b ) );
          }
    lcm = c / gcd * d;
    cout << gcd << lcm ;
}
Prabakar 77 Posting Whiz

Yes