Aquí esta resuleto correctamente el examen de segundo parcial, y con las instrucciones de como realizarlo:
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.
//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);
}
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;
}
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 21.Note that the first two fibonacci numbers are 0 and All others are the sum of the




two fibonacci numbers.
//CODE:
// Ever Olivares
#include <iostream>
using namespace std;
long fibonacci(long n){
long i=0,a=1,b=1,c=0;
if (n<2){
return n;
}
if (n==2){
return 1;
}
while(i<n-2)
{
c=a+b;
a=b; b=c;
i++;}
return c;
}
int main(){
long n;
cout<< “Type the number ” << endl;
cin >> n;
cout << “The Fibonacci ” << n << ” position of the serie is: ” << endl;
cout<<fibonacci(n)<<endl;
return 0;
}
QUESTION 4:
Write a function called isPalindrome which receives a string “x” and returns true if the string x is a palindrome, otherwise false.
//CODE:
// Ever Oliavres
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
string word, fin;
string is_palindrome(string word)
{
string backwards;
cout << “Type a word: n”;
cin >> word;
int large = word.length();
for (int x = large – 1; x >= 0; x–)
{
backwards += word[x];
}
if (backwards == word)
{
fin = “Your word is a palindrome”;
}
else
fin = “Your word is not a palindrome”;
return fin;
}
int main()
{
cout << is_palindrome(fin);
}
WSQ13- 2 Parcial by lilihecblog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.