"Until" Algorithm 
Author Message
 "Until" Algorithm

Let's say we want to build an algorithm that will do the following
Lets sugget Xn=a*n
1. Calculate a value Xn.
2. Calculate a value X2n by multiplying by 2 the modifier n.
3. Calculate the value Y(Xn,X2n).
4. Compare value Y with another W.
5. Keep on looping UNTIL W>=Y?---That's where I get trouble!
6. If it reaches that point then prints the value Xn THERE.

could some one suggest a good implimentation of this algorithm in ANSI C

thanx for the help
Marios Fotiou



Wed, 25 Apr 2001 03:00:00 GMT  
 "Until" Algorithm
[posted and mailed]

Quote:

>Let's say we want to build an algorithm that will do the following
>Lets sugget Xn=a*n
>1. Calculate a value Xn.
>2. Calculate a value X2n by multiplying by 2 the modifier n.
>3. Calculate the value Y(Xn,X2n).
>4. Compare value Y with another W.
>5. Keep on looping UNTIL W>=Y?---That's where I get trouble!
>6. If it reaches that point then prints the value Xn THERE.

>could some one suggest a good implimentation of this algorithm in ANSI C

This sort of thing is what 'do { ... } while' is for.

  do {

    /* steps 1 - 3 */

  } while ( W < Y );

  /* step 6 */

-- Mat.



Wed, 25 Apr 2001 03:00:00 GMT  
 "Until" Algorithm


Quote:
>Let's say we want to build an algorithm that will do the following
>Lets sugget Xn=a*n
>1. Calculate a value Xn.
>2. Calculate a value X2n by multiplying by 2 the modifier n.
>3. Calculate the value Y(Xn,X2n).
>4. Compare value Y with another W.
>5. Keep on looping UNTIL W>=Y?---That's where I get trouble!
>6. If it reaches that point then prints the value Xn THERE.

>could some one suggest a good implimentation of this algorithm in ANSI C

We're not going to do your homework for you. However if you post what you
have already I'm sure somebody will be happy to point out where you are
going wrong if you are) and point you in the right direction.

--
-----------------------------------------


-----------------------------------------



Wed, 25 Apr 2001 03:00:00 GMT  
 "Until" Algorithm
If you really need 'until':

#define until(a)    while (!(a))

e.g.

    do
    {
        /* Your code here */
    }
    until (w >= y);

The macro will fail if the comma operator is used in the body of the until
expression. In C9X you will be able to use the following:

#define until(...)    while (!(_VAR_ARGS_))

(from memory, it may be __VAR_ARGS, or something similar)

Russell

Marios Fotiou wrote ...
...

Quote:
>5. Keep on looping UNTIL W>=Y?---That's where I get trouble!

...


Thu, 26 Apr 2001 03:00:00 GMT  
 "Until" Algorithm
Quote:

> If you really need 'until':

> #define until(a)    while (!(a))

<snip>
You can also #define begin {
             #define end }
and make it look like another language.

The problem is that it will confuse other C programmers that have to
maintain your code.

C programmers will have no problem understanding while(!( W>=Y )) or
while( W<Y )
--
Bill Roeder
My opinions are my own and do not reflect those of my employer.
Why do people put the above line in their signature?
If they reflected my employer then he would have sent the message!



Sat, 28 Apr 2001 03:00:00 GMT  
 "Until" Algorithm
Groovy hepcat Marios Fotiou was jivin' on Sat, 07 Nov 1998 20:23:42
+0000 in comp.lang.c.
"Until" Algorithm's a cool scene! Dig it!

Quote:
>Let's say we want to build an algorithm that will do the following
>Lets sugget Xn=a*n
>1. Calculate a value Xn.
>2. Calculate a value X2n by multiplying by 2 the modifier n.
>3. Calculate the value Y(Xn,X2n).
>4. Compare value Y with another W.
>5. Keep on looping UNTIL W>=Y?---That's where I get trouble!

  Well, what's the problem? What are you doing that doesn't seem to be
working? Please be specific so we know how to help you.

Quote:
>6. If it reaches that point then prints the value Xn THERE.

>could some one suggest a good implimentation of this algorithm in ANSI C

  An easy way to implement a do...until(condition true) construct is
to use do...while(condition not true). Eg.:

int y, w;
do
{
  /* calculation of y and w */

Quote:
} while(w < y);

--

----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----

-------------- Shaggy was here! ---------------
    http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============



Fri, 04 May 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Get number until 2 int after ","

2. Question on implementing "repeat...until keypress"?

3. Comments on "Algorithm in C" or "Algorithm in C++"

4. C_"permutations algorithm"

5. Algorithm for "diff"ing files/strings

6. Algorithm for "bit copy" function

7. Wanted: "tick" algorithm for graph axis

8. "Best fit" algorithm (help)

9. source code in "Algorithms in C"

10. remove() vrs fopen("""w")

11. Displaying binary data as ascii "1"'s and "0"'s

12. Looking for "Shroud"/"Obfus"

 

 
Powered by phpBB® Forum Software