WSQ11 – Yo soy 196

In this WSQ we need to create a program that asks the user for two pieces of data:

  • The lower bound of the sequence
  • The upper bound of the sequence
Then it check the values from the lower bound (inclusive) to the upper bound (inclusive) and make a report of them. During the analysis of each number, if a Lychrel number is found it should be reported immediately with something like “Found a Lychrel number: 196”
Here is a link to the code in Github.
Python/WSQ-11(Palindromes)
This one is the most difficult of the WSQ and i had a lot of problems iterating them and comparing them.

WSQ10 – Lists

This is the WSQ where we need to create a program that ask for 10 numbers and it needs to store it in a list. The program need to show the total, the average and the standard deviation of those numbers.

For this program I used the math library to calculate the square root for the standard deviation.

Here is a picture of the code.

WSQ10

Here is the code running on cygwin.

WSQ10Cyg

Here is the link to the code in Github.

Python/WSQ-10 (Lists)

 

Word count WSQ12

Here is my blog post for the WSQ 12.

Create a program that asks the user for a word which will be your search word and the name of a file to open and search for that word. Then create a function that will receive two parameters (both string) representing those two data points. This function returns the number of occurrences of that word in that file. Here is the link to my GitHub.

 

Captura de pantalla 2016-05-04 a las 11.14.45 p.m..png

#WSQ13-Partial exam 2

Here is the partial exam answered of course jajajaja so the exam just had four questions and I will list them in order.

QUESTION 1:

Write a function called triangles which receives a single parameter (int) which represents the size of a triangle as explained below. The function should print a triangle using loops (for or while). The only characters printed here are ‘T’ and the new-line character. The first line is length one, the middle line is length size and the last line is length one. The example below is for size 6.

      T
      TT
      TTT
      TTTT
      TTTTT
      TTTTTT
      TTTTTT
      TTTTT
      TTTT
      TTT
      TT
      T

//CODE

// Ever Olivares
#include <stdio.h>
#include <iostream>
using namespace std;

int triangle (int x)
{
for (int i=1; i<=x ;i++)
{
for (int j=1; j<i+1; j++)
cout <<“T”; cout <<endl;
}
for (int i=x-1; i>=1; i–)
{
for (int j=1; j<i+1; j++)
cout <<“T”; cout <<endl;
}
return 0;
}
int main ()
{
int y;
std::cout<<“type the numbers of T you want” <<std::endl;
std::cin >> y;
triangle (y);
}

Captura de pantalla 2016-04-30 a las 21.38.49.png

QUESTION 2:

Write a function called superpower that has two parameters of type long and returns a long which is first parameter raised to the power of the second, which is to say it returns ab So, superpower(3,4) would return 81.

//CODE:

// Ever Oliavres
#include <iostream>
#include <cmath>

void superpower(int num1, int num2){
int R;
R= pow(3,4);
std::cout << “The result is… “<<R << std::endl;
}

int main(int argc, char const *argv[]) {
int R;
superpower(3,4);

return 0;
}

Captura de pantalla 2016-04-30 a las 21.40.17.png

QUESTION 3:

Write a function called fibonacci which receives a long “n” and returns a long which is the value of the nth number in the fibonacci series which is: 0,1,1,2,3,5,8,13,21,34,55,89…………So, fibonacci(0) would return 0. fibonacci(5) would return 5, fibonacci(8) would return

Captura de pantalla 2016-04-30 a las 21.42.16.png
Captura de pantalla 2016-04-30 a las 21.43.21.png

Continue reading “#WSQ13-Partial exam 2”

#WSQ10-Lists

In this WSQ I used arrays of numbers to calculate via functions some mathematical operations given, for example to calculate the total, average and standard deviation of those numbers.

 

//CODE

#include <iostream>
#include <cmath>
using namespace std;

float total(float numbers[], int howMany){
float t = 0;
for (int num=0; num<howMany; num++){
t = t + numbers[num];
}
return t;
}

float average(float numbers[],int howMany){
float sum=0.0,prom=0.0;
for (int i=0; i<howMany;i++){
sum+=number[i];
}
prom=sum/howMany;
return prom;
}

float standarddeviation(float numbers[], int howMany){
float variation= 0.0, sum=0.0,prom=0.0,deviation=0.0;
for (int i=0;i<howMany;i++){
sum+=number[i];
}
prom=sum/total_num;
for(int i=0;i<howMany;i++){
variation=variation+pow((number[i]-prom),2);
}
deviation=sqrt(variation/howMany);
return deviation;
}

int main(int argc, char const *argv[]) {
float n, t, a, sd;

float num[10];
std::cout << “Enter 10 numbers Please.” << std::endl;
for (int i=0; i<10; i++){
std::cin >> n;
num[i]=n;
}
std::cout << ” Total,average,stdev of your numbers are..”;
t=total(num,10);
a=average(num,10);
sd=standarddeviation(num,10);
cout << t << std::endl;
cout << a << std::endl;
cout << sd << std::endl;
return 0;
}

Captura de pantalla 2016-04-30 a las 20.58.02Captura de pantalla 2016-04-30 a las 20.58.15

#WSQ14

“Scilab”

Scilab es un paquete de código libre, que se basa en cálculos numéricos, se encarga de operaciones de matrices y en ámbitos científicos y de ingeniería, tiene cientos de funciones, tanto de propósito general,como especializado, ademas de contar con una excelente interfaz gráfica.

Scilab_logo

  • En scilab se pueden ejecutar comandos directamente en la consola y obtener el resultado en forma inmediata, por ejemplo realice una suma una resta una multiplicación y una división.

uno

A través del comando “clc” podemos limpiar la consola ademas de contar con un historial de todos los comandos que hemos hecho.

 

  • Podemos hacer declaraciones de variables en la consola, para ver el valor de la variable simplemente se escribe su nombre y un enter, el sistema siempre da una re-alimentación, pero si quieres quitarla basta con escribir un punto y coma. ” ; “
  • En scilab para eliminar una variable no solamente la borras, tienes que escribir “clear” seguido del nombre de la variable. para eliminar todas las variables simplemente se escribe “clear”

Dos

  • Scilab cuenta con variables predefinidas como el valor de pi, el valor del numero e e inclusive el numero imaginario i .

tres

  • También podemos hacer operaciones con raíces cuadradas, con identidades trigonométricas, valores absolutos, tangentes hiperbólicas, entre muchas otras mas.

cuatro.png

  • Hay muchas cosas divertidas para hacer en scilab, por ejemplo podemos crear un número aleatorio, lo hacemos usando diferentes funciones, por ejemplo usando rand() para el número aleatorio, y round() para redondearlo. para elegir un rango de numeros multiplicamos round() por el valor mas alto del rango.

cinco.png

  • Scilab permite la manipulación de vectores, para declarar un vector fila escribimos la variable seguida de los valores separados por espacios englobados entre corchetes, para vectores columna hacemos lo mismo pero los separamos por punto y coma.

seis.png

Exam2 WSQ13

Well kind of late but here are my codes from the partial exam,  I will leave links for my codes in Github, hopefully you’ll find useful.

  1. Write a function called triangles which receives a single parameter (int) which represents the size of a triangle. The function should print a triangle using loops (for or while). The only characters printed here are ‘T’ and the new-line character. The first line is length one, the middle line is length size and the last line is length one. Link to GitHub

Captura de pantalla 2016-04-27 a las 9.54.41 p.m..png

  1. Write a function called superpower that has two parameters of type long and returns a long which is first parameter raised to the power of the second, which is to say it returns a^b. Link to GitHub

    Captura de pantalla 2016-04-27 a las 9.59.14 p.m..png 

  2. Write a function called fibonacci which receives a long “n” and returns a long which is the value of the nth number in the fibonacci series which is: 0,1,1,2,3,5,8,13,21,34,55,89…………
    So, fibonacci(0) would return 0. fibonacci(5) would return 5, fibonacci(8) would return 21.
    Note that the first two fibonacci numbers are 0 and 1.
    All others are the sum of the previous two fibonacci numbers. Link to GitHub

    Captura de pantalla 2016-04-27 a las 10.02.25 p.m..png

  1. Write a function called isPalindrome which receives a string “x” and returns true if the string x is a palindrome, otherwise false. Lint to GitHub

    Captura de pantalla 2016-04-27 a las 10.04.27 p.m..png

#WSQ13

“Exam 2”

Fundamentals of Programming, First Partial Examination

Thursday, April 7, 2015

1. Escribe el función distancia cual recibe 4 números (x1, y1, x2, y2) cuales representan dos puntos en espacio (x1,y1) y (x2,y2). El método debe regresar la distancia entre los dos puntos. Recuerda que el valor cuadrada del hipotenusa del triangulo es igual que la suma de las cuadradas de los otro dos lados del triangulo (the hypotenuse squared is equal to the sum of the squares of the other two sides).

for_dist_2_ptos

Aquí está mi código funcionando:

import math

def distancia (x1,y1,x2,y2):
resultado=math.sqrt((x2+x1)**2+(y2+y1)**2)
return resultado

fin=distancia(1,2,3,4)
print(fin)

Por aquí el enlace a Github.

2. Escribe un función que se llama triangulo cual recibe un parámetro size y imprime un triangulo derecho como el siguiente. El renglón mas grande debe llevar size numero de “T”. SOLO imprime los “T”s y los endlines. Nota que no hay characteres (espacios) a la derecha de los T’s. Debe usar un ciclo “for” para controlar el repetición. Ejemplo es si size era 6.

Aquí está mi código:

numero=int(input(“Por favor dame el tamaño de tu triangulo “))

def triangulo (var):
r=range(1,var)
r2=range(var,0,-1)

          for x in r:
resultado=“T”*x
                    print(resultado)

          for y in r2:
otra=“T”*y
                    print(otra)

triangulo(numero)

 Por aquí el enlace a Github.

3. Escribe un función que se llama superpower(a,b) con dos parameters de (enteros / int). Debe regresar el valor del primer parametro al poder del segundo, o mejor decir a b . No puedes

Continue reading “#WSQ13”

Lists WSQ10

Hello everyone! this WSQ is different, well kind of, what to d0:

Create a program that asks the user for 10 numbers. Store those numbers in a list. Show to the user the total, average and standard deviation of those numbers. I found some very useful videos and tutorials:

 

Captura de pantalla 2016-04-07 a las 10.40.28 a.m.

 

Captura de pantalla 2016-04-07 a las 10.37.25 a.m.

Well finally this is the link for my code in GitHub.