Tag Archives: #WSQ07

#WSQ07 #TC1017 Sumatories and loops!

Welp, my explains how the commands “while” and “for” work on C++! You can check it out at the newest episode of ++Adventures, right here!

WSQO7

Don’t know why this one took me so long…

WSQO7

WSQO7

Sum of Numbers (‘for’ loops)

The next program ask the user for two numbers, the first is the lower limit of a range of numbers, and the second is the maximum. The program then takes all the numbers in the given range and makes the sum of all the numbers in the given interval, including the limits.

The source code is the given:

of Numbers

 

n1=int(input(“Enter the lower limit of the range “))

n2=int(input(“Enter the higher limit of the range “))

 

if(n2<n1):

    print(“The lower limit must be a lower number than the second”)

sumnum=0

 

for num in range(n1,n2+1):

    sumnum=sumnum+num

 

print(“The sum is “,sumnum)

The first thing the program does is validate that the user don’t crash the program, it simply applies a conditional that tells the user that the inputs are incorrect, thus the program wont do nothing.

In the program we can see a for loop. The for loop is used when we know how many times we are going to be in a loop, or when we need a given variable that will be incremented in every run that we make of the loop. This is used very often to navigate inside arrays and other arranges. 

The for loop in Python is used in conjuction with the range command, wich gives us an array of integers when we type the lower and the upper limit; but beware, the upper limit is not inclusive, thus you must use a +1.

Then the program uses this loop and navigates the array adding to the accumulative of the two numbers before the next number in the array, thus making the sum of all the numbers in the array. 

At the end the program prints the accumulative sum of all the integers in the array. 

This is for my of my

WSQ07

WSQ07 – Sumas de Numeros en Serie

#WSQ07

In this assignment we had to use a loop to sum a number that the user chooses with every number in the middle of it and another maller number that the user chooses too. In order to do what mentioned, I would switch the part of the algorithm in charge of it.( the signs and mathematic algorithms)

Here’s my code:

https://github.com/JuanPabloGonzalezHuezzo/-WSQ07/blob/master/WSQ07

 

or here too:

<iostream>
using namespace std;
int main (){
  int x, y, z, ch, res, su;

  do{
    cout << “Introduce el número más chico.” << endl;
    cin >> x;
    cout << “introduce el número mayor.” << endl;
    cin >> y;

      if (x<y){
        ch=0;
      }

        else {
          cout << endl <<“escribiste los números de manera incorrecta, intenta de nuevo.” << endl;
          ch=10;
        }
} while (ch==10);
  if(ch==0)
    z=(y-x)+1;
    su=0;
    for (int i=0; i<z; i++){
    res=(x+i);
    su=su+res;
    }
        cout << “La suma de ” << x << ” hasta ” << y <<” es equivalente a ” << su;
return 0;
}

#WSQ07 #TC1014

For this programm I used a while loop.

Learn To Program 2015-02-16 22:40:00

WSQ07
La utilización de loops en cualquier programa es demasiado importante cuando el programa debe hacer una misma tarea por una cantidad definida de ocasiones. Pero se debe tener cuidado al momento de utilizar esta característica, pues si redacta mal, el programa entra en un bucle infinito sin salida. Cuestión de practica para dominar completamente los loops.
Utilice la siguiente pagina para redactar loops en Python:
http://www.tutorialspoint.com/python/python_while_loop.htm

**********************
Programa hecho en Python:
**********************
https://gist.githubusercontent.com/A01630323/cc41587a97c2f19a0bd2/raw/15bb71c8dcc8577e4e2f1edce5ee9615bc7983c1/WSQ07

Learn To Program 2015-02-16 22:40:00

WSQ07
La utilización de loops en cualquier programa es demasiado importante cuando el programa debe hacer una misma tarea por una cantidad definida de ocasiones. Pero se debe tener cuidado al momento de utilizar esta característica, pues si redacta mal, el programa entra en un bucle infinito sin salida. Cuestión de practica para dominar completamente los loops.
Utilice la siguiente pagina para redactar loops en Python:
http://www.tutorialspoint.com/python/python_while_loop.htm

**********************
Programa hecho en Python:
**********************
https://gist.githubusercontent.com/A01630323/cc41587a97c2f19a0bd2/raw/15bb71c8dcc8577e4e2f1edce5ee9615bc7983c1/WSQ07

Sum of Numbers

I made a program that sums the numbers within a range given by the user! Check it out.