Algorithm

Hi,i am new to c++ and i have understood some basic concepts of c++.But i have problem writing out algorithm.if you would tell me how and give more examples,it would be very helpful.

Last edited on
An algorithm is in essence a set of instructions to accomplish some particular task. How detail the instruction goes depends on the writer. To give a really solid example are the cooking instructions in any cookbook you know where it is

- turn oven on
- place ingredients 1 and 2 in bowl
- mix ingredients 1 and 2
-place ingredient 3 on cupboard
- knead ingredient 3
and so forth until the finished product.

It is the same idea for writing a program. The idea is too write a set of instructions that explain how the program is going to be built. For example,
if we try to build a program that saves a user input.
The algorithm might go:

print a message telling user input whatever data
set up variable so data can be stored
place input data into variable
repeat data back to user.

Also there are some decent youtube explanations of how to employ algorithm as I realize this may not be the best explanation. However, using the cooking instructions as an example is usually the best way to think about it. So in essence an algorithm is just a way to organize our thoughts on how and what we want to accomplish with our program.
Last edited on
An algorithm for what? An algorithm could be anything.
al·go·rithm  
/ˈalgəˌriT͟Həm/
Noun
A process or set of rules to be followed in calculations or other problem-solving operations, esp. by a computer.

You could be looking for anything from finding the area of a square
1
2
3
4
int area( const int &x , const int &y )
{
    return( x * y );
}

to something that is finding how long it will take until the next solar eclipse or something.
Topic archived. No new replies allowed.