Quiz Week 8

--Originally published at Let's CODE

This class we were oredered to write a code that generates the Fibonacci series. I was a really challenging task, ’cause my logic didn’t adapted to the situation righly. Finally I used some loops, vectors and a function to make it work. This is what I wrote. #include <iostream> using namespace std; int fibonacci(int n) … Continue reading Quiz Week 8

Fibonacci is awesome!

--Originally published at Programming Path

My mom always told me about the Fibonacci patterns in nature and how beautiful they are as well that it is so interesting that it’s all mathematics!

I’ve found a TED talk that explain in a very easy way to understand the Fibonacci series. I recommend you to watch it.

The quiz today was precisely of doing a function that gives you a Fibonacci number. What I did was to ask the user a number, and I return the Fibonacci number, or at least that was my intention of asking, but I think that my question isn’t the correct one.

*Just a note. The first Fibonacci numbers are the next one:

0  1  1  2  3  5  8  13  21  34  55  89…

Here is my code:

quiz6

And the result was this:

Enter the number of numbers you want to know of Fibonacci numbers: 10
fibonacci number: 55.

Another try:

Enter the number of numbers you want to know of Fibonacci numbers: 2
fibonacci number: 1.

Thanks for reading.


Quiz #6

--Originally published at Programming

Well in this quiz ask for various activities, so its good to practice.

Important things:

  • Note that you will also need to include <stdio.h>
  • printf will also complain that you are not passing an int to the %d so perhaps you want to cast the sizeof value to an int like this:

int(sizeof(c)*8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For the first exercise:

Type in the following program and run it:

#include 
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
	char c;  
	short s;  
	int i;  
	unsigned int ui;  
	unsigned long int ul; 
	float f;
	double d;  
	long double ld;  
	cout << endl 
  	     << "The storage space for each variable type is:"
	     << endl;
	cout << endl << "char: \t\t\t%d bits",sizeof(c)*8;  //  \t means tab 
	cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
	cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
	cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
	cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
	cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
	cout << endl << "double: \t\t%d bits",sizeof(d)*8;
	cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;

q61

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For the second exercise:

Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

	Input a single character, followed by : h
	Input an integer, followed by :  4872
	Input a float, followed by :  182.937
	The character h when cast to an int gives value ?????
	The character h when cast to a float gives value ?????
	The integer 4872 when cast to a char gives value ?
	The integer 4872 when cast to a float gives value ?????
	The float 182.937 when cast to a char gives value ?
	The float 182.937 when cast to an 
q62
q63
q64
q65
Continue reading "Quiz #6"

Quiz (Week 6)

--Originally published at Programming Path

Well… this was a bit large but I did it. I just didn’t made the post because of partials and to be honest, I forgot that we had quiz and I did not publish it, but here I am.

The quiz had 5 problems, so I will post a lot of photos and codes.

The first problem was this:

Type in the following program and run it:

#include 
main()
{ /* PROGRAM TO PRINT OUT SPACE RESERVED FOR VARIABLES */
	char c;  
	short s;  
	int i;  
	unsigned int ui;  
	unsigned long int ul; 
	float f;
	double d;  
	long double ld;  
	cout << endl 
  	     << "The storage space for each variable type is:"
	     << endl;
	cout << endl << "char: \t\t\t%d bits",sizeof(c)*8;  //  \t means tab 
	cout << endl << "short: \t\t\t%d bits",sizeof(s)*8;
	cout << endl << "int: \t\t\t%d bits",sizeof(i)*8;
	cout << endl << "unsigned int: \t\t%d bits",sizeof(ui)*8;
	cout << endl << "unsigned long int: \t%d bits",sizeof(ul)*8;
	cout << endl << "float: \t\t\t%d bits",sizeof(f)*8;
	cout << endl << "double: \t\t%d bits",sizeof(d)*8;
	cout << endl << "long double: \t\t%d bits",sizeof(ld)*8;

This was pretty easy. I just needed to write the same code but in c++. Here is the picture:

quiz5-1

Second problem:

Write a program to read in a character, an integer, and a float, and print out the values, then cast to other types; so that the interaction with the user is something like the following:

	Input a single character, followed by : h
	Input an integer, followed by :  4872
	Input a float, followed by :  182.937
	The character h when cast to an int gives value ?????
	The character h when cast to a float gives value ?????
	The integer 4872 when cast to a char gives value ?
	The integer 4872 when cast to a float gives value ?????
	The float 182.
quiz5-2
quiz5-3
quiz5-4
quiz5-5
Continue reading "Quiz (Week 6)"

Quiz #5

--Originally published at my programming blog

The quiz of this week was very tricky, I needed to do the first 5 exercises in this page, at first I was a little bit confused with the first two exercises, but once the teacher explained me it was that hard.

  1. For the first exercise I tested the code and tried to correct it based on the errors the terminal gave me, then thanks to Ken and the page he gave us, I was able to correct the program completely.

screen-shot-2017-02-15-at-3-38-22-pm

2. For the second exercise I asked the user for an integer, a character and a float, and I made an integer called x that would be equal to the integer/character/float converted. So what I did was to equal x to “(type) a” where a= to the value that the user enters (the int, float or char). I did this before each message that the program prints, changing the value of x each time. I learned this method thanks to this page.

screen-shot-2017-02-15-at-3-39-06-pm

3. In the third exercise what I needed to do was to make a program that could print this:

Screen Shot 2017-02-16 at 9.39.47 AM.png

What I did was to do it from scratch, counting spaces etc. It was a bad idea!! Because I wasted a lot of time and when I finished  Ken told the class that by copy pasting it it would be very easy, which made me mad because I didn’t think about that. screen-shot-2017-02-15-at-3-39-44-pm

4. For the fourth exercise needed to ask the user for three numbers and then print those numbers but in ascending order. What I did was well first to ask the user for the three numbers, then I did nested ifs, for example: My first if’s condition was if a>b and inside that if I entered another if with the condition if b>c and then

screen-shot-2017-02-15-at-3-40-04-pm
screen-shot-2017-02-15-at-3-40-19-pm
screen-shot-2017-02-15-at-3-40-37-pm
screen-shot-2017-02-15-at-3-37-45-pm
Continue reading "Quiz #5"

QuizWK4

--Originally published at TC1017

The program get the minimum number out of three then sum the squares of all three numbers.

#BAPL

Link to the code: https://docs.google.com/document/d/1Q5U8Isn3j38o1WOfCftsPgF6gKVVdXaWd7hmcTejyHE/edit?usp=sharing


Quiz Week 6: Multiple exercises in an only quiz

--Originally published at Let&#039;s CODE

The quiz for today consited in five exercises that we had to do during the class, which came from a page called C/C++ PROGRAMMING EXERCISES (they were the first five ones). In the first problem, we had to modify a determinated code to make it work. The original code was: #include main() { /* PROGRAM … Continue reading Quiz Week 6: Multiple exercises in an only quiz

Quiz Week 6: Multiple exercises in an only quiz

--Originally published at Let&#039;s CODE

The quiz for today consited in five exercises that we had to do during the class, which came from a page called C/C++ PROGRAMMING EXERCISES (they were the first five ones). In the first problem, we had to modify a determinated code to make it work. The original code was: #include main() { /* PROGRAM … Continue reading Quiz Week 6: Multiple exercises in an only quiz

Quiz #3

--Originally published at Programming

For this quiz the instruction was:

Create a program with two functions:
  • double square_root(double x) {}  // returns the square root of x
  • double cube_root(double x) {} // returns the cube root of x

You need to include the library <math.h> and use sqrt, cbrt.

 

quiz3

#Quiz03