Tag Archives: #000000

Hey gusy here is my WSQ10

Mastery 10

Basic output (printing) and inpur (text based) in C++

The standard library defines a handful of stream objects that can be used to access what are considered the standard sources and destinations of characters by the environment where the program runs:

stream description
cin standard input stream
cout standard output stream
cerr standard error (output) stream
clog standard logging (output) stream

Standard output (cout)

On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout.

For formatted output operations, cout is used together with the insertion operator, which is written as << (i.e., two “less than” signs).

cout << "Output sentence"; // prints Output sentence on screen
cout << 120;               // prints number 120 on screen
cout << x;                 // prints the value of x on screen  

Standard input (cin)

In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin.

For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example:

int age;
cin >> age;

#TC1017 #WSQ13 Babylonian Method

Babylonian Method

For this work I take reference the following link..

http://es.wikipedia.org/wiki/Cálculo_de_la_ra%C3%ADz_cuadrada#Algoritmo_babil.C3.B3nico

This link helped me to understand the procedure :D!!!

Here is to Github:

https://github.com/alejcbgmz/WSQ-s-Ale-Jcb-Gmz/blob/master/WSQ13.cpp

 It’s not as complicated as it seems

#TC1017 #Mastery22 – When to use what type of repetition in a program

There are two approaches to writing repetitive algorithms. 

      1. Loops (Iteration)
      2. Recursion. 

Iteration: Use for loops, do..while, while loops.

Example: Factorial of a number

int factorial(int num)
{
      int k=num;
      while(num != 0)
      {
            k=k*(num-1);
            num–;
      }
      return num;
}

—————————————————————————————————–

Recursion: Recursion is a repetitive process in which a function calls itself. 

Limitations of Recursive Approach:
      1. Recursive solutions may involve extensive overhead because they use function calls. Each function call requires push of return memory address, parameters, returned result,etc. and every function return requires that many pops. 
      2. Each time you call a function you use up some of your memory allocation may be in stack or heap. If there are large number of recursive calls – then you may run out of memory. 

Example:

int factorial(int num)
{
      if(num != 0)
      {
            num=num*factorial(num-1);
      }
      return num;
}

When to Use:
For large number of iterations, use loops(iterative approach).
For small number of iterations, use recursion.

Euclides

Hi guys here’s my

I had some problems because, I had some mistakes, but my compiler in Windows let me run the program and actually gave me the correct answer. So I have to swich to work in my mac and fix the problem.

here´s my code.

https://gist.github.com/samir96/ac1b460ae54bc0fdce6e