SlideShare a Scribd company logo
1 of 7
Download to read offline
TRABAJO ENCARGADO N° 2
Lenguaje de Programación
ESTUDIANTE: Rene Suaña Coila SEMESTRE: III
1. Muestre el valor de x después de ejecutar cada una de las
siguientes instrucciones:
a) x =fabs( 7.5 );
b) x = floor( 7.5 );
c) x = fabs( 0.0 );
d) x = ceil( 0.0 );
e) x = fabs( -6.4 );
f) x = ceil( -6.4 );
g) x =ceil( -fabs( -8 + floor( -5.5 ) ) )
#include <iostream>
#include <math.h>
using namespace std;
double valor1 (double x)
{
cout<< " El valor de x=fabs(7.5) "<< " es ";
return fabs (x);
}
int valor2 (double x)
{
cout << " El valor de x = floor( 7.5 ) "<< " es ";
return floor(x);
}
int valor3 (double x)
{
cout<< " EL valor de x = fabs( 0.0 ) "<< " es ";
return fabs (x);
}
int valor4 (double x)
{
cout << " El valor de x = ceil( 0.0 ) " << " es: ";
return ceil(x);
}
int valor5 (double x)
{
cout<< " EL valor de x = fabs( -6.4 ) "<< " es: ";
return fabs (x);
}
int valor6 (double x)
{
cout << " El valor de x = ceil( -6.4 ) "<< " es: ";
return ceil(x);
}
int valor7 (double x)
{
cout<< " El valor de x =ceil( -fabs( -8 + floor( -5.5 ) ) ) "<<" es:
";
return ceil(-fabs(-8+floor(x)));
}
int main ()
{
cout<<valor1(7.5)<<endl;
cout<<valor2(7.5)<<endl;
cout<<valor3(0.0)<<endl;
cout<<valor4(0.0)<<endl;
cout<<valor5(-6.4)<<endl;
cout<<valor6(-6.4)<<endl;
cout<<valor7(-5.5)<<endl;
}
2. Un estacionamiento cobra una cuota mínima de $2.00 por
estacionarse hasta tres horas. El estacionamiento cobra
$0.50 adicional por cada hora o fracción que se pase de tres horas.
El cargo máximo para cualquier periodo dado de 24 horas
es de $10.00. Suponga que ningún auto se estaciona durante más de 24
horas a la vez. Escriba un programa que calcule y muestre
los cargos por estacionamiento para cada uno de tres clientes que
estacionaron su auto ayer en este estacionamiento. Debe
Introducir las horas de estacionamiento para cada cliente. El
programa debe imprimir los resultados en un formato tabular
Ordenado, debe calcular e imprimir el total de los recibos de ayer.
El programa debe utilizar la función calcularCargos para
Determinar el cargo para cada cliente. Sus resultados deben aparecer
en el siguiente formato:
Auto Horas Cargo
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
TOTAL 29.50 14.50
#include <iostream>
using namespace std;
float calcularCargo(float x);
int main ()
{
float horas1;
float horas2;
float horas3;
float cargo1;
float cargo2;
float cargo3;
float totalhoras;
float totalcargo;
cout<< " Horas del Auto 1: ";
cin>>horas1;
cout<< " Horas del Auto 2: ";
cin>>horas2;
cout<< " Horas del Auto 3: ";
cin>>horas3;
cout<< " nAuto " << " Horas "<< " Cargon ";
cout<<"1";
cargo1=calcularCargo(horas1);
cout<<"n 2";
cargo2=calcularCargo(horas2);
cout<<"n 3";
cargo3=calcularCargo(horas3);
totalhoras = horas1 + horas2 + horas3;
totalcargo = cargo1 + cargo2 + cargo3;
cout<< " nTotal "<<"t"<<totalhoras<<"t"<<totalcargo;
return 0;
}
float calcularCargo(float x)
{
cout<<"t"<<x;
if((float)x <=3)
{
cout<<"t"<<2.0;
return 2.0;
}
else
{
if((int)x == 24)
{
cout<<"t"<<10.0;
return 10.0;
}
else
{
cout<<"t"<<(((float) x-3)*0.5)+2;
return (((float)x-3)*0.5)+2;
}
}
}
3. Una aplicación de la función floor es redondear un valor al
siguiente entero. La instrucción
y = floor( x + .5 );
redondea el número x al entero más cercano y asigna el resultado a y.
Escriba un programa que lea varios números y que utilice
la instrucción anterior para redondear cada uno de los números a su
entero más cercano. Para cada número procesado, muestre
tanto el número original como el redondeado.
#include <iostream>
#include <math.h>
using namespace std;
double EnteroCercano(double x);
int main ()
{
double (x);
cout<< " Ingrese un numero: ";
cin>>x;
cout<<x<<"t";
cout<<EnteroCercano(x);
}
double EnteroCercano(double x)
{
return floor(x+0.5);
}
4. La función floor puede utilizarse para redondear un número hasta
un lugar decimal específi co. La instrucción
y = floor( x * 10 + .5 ) / 10;
redondea x en la posición de las décimas (es decir, la primera
posición a la derecha del punto decimal). La instrucción
y = floor( x * 100 + 0.5 ) / 100;
redondea x en la posición de las centésimas (es decir, la segunda
posición a la derecha del punto decimal). Escriba un programa
que defi na cuatro funciones para redondear un número x en varias
formas:
a) redondearAEntero( numero )
b) redondearADecimas( numero )
c) redondearACentesimas( numero )
d) redondearAMilesimas( numero )
Para cada valor leído, su programa debe imprimir el valor original,
el número redondeado al entero más cercano, el
número redondeado a la décima más cercana, el número redondeado a la
centésima más cercana y el número redondeado a la
milésima más cercana.
#include <iostream>
#include <math.h>
using namespace std;
double redondearAEntero(double x)
{
return floor((x+0.5));
}
double redondearADecimas(double x)
{
return floor((x*10+0.5)/10);
}
double redondearACentesimas (double x)
{
return floor((x*100+0.5)/100);
}
double redondearAMilesimas (double x)
{
return floor((x*1000+0.5)/1000);
}
int main()
{
double numero;
cout<< " Ingrese un numero: ";
cin>>numero;
cout<<redondearAEntero(numero)<<" Entero "<<endl;
cout<<redondearADecimas(numero)<<" Decimas "<<endl;
cout<<redondearACentesimas(numero)<< " Centesimas "<<endl;
cout<<redondearAMilesimas(numero)<< " Milesimas "<<endl;
}
5. Escriba instrucciones que asignen enteros aleatorios a la variable
n en los siguientes rangos:
a) 1 ≤ n ≤ 2
b) 1 ≤ n ≤ 100
c) 0 ≤ n ≤ 9
d) 1000 ≤ n ≤ 1112
e) –1 ≤ n ≤ 1
f) –3 ≤ n ≤ 11
#include <ostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
cout<< " a: ";
cout<<setw(1)<<(1+rand()%2)<<endl;
cout<< " b: ";
cout<<setw(1)<<(1+rand()%100)<<endl;
cout<< " c: ";
cout<<setw(1)<<(0+rand()%9)<<endl;
cout<< " d: ";
cout<<setw(1)<<(1000+rand()%1112)<<endl;
cout<< " e: ";
cout<<setw(1)<<(-1+rand()%1)<<endl;
cout<< " f: ";
cout<<setw(1)<<(-3+rand()%11)<<endl;
}
6. Escriba una función llamada enteroPotencia( base, exponente ) que
devuelva el valor de
base exponente
Por ejemplo, enteroPotencia( 3, 4 ) = 3 * 3 * 3 * 3. Suponga que
exponente es un entero positivo distinto de cero y que
base es un entero. La función enteroPotencia debe utilizar un ciclo
for o while para controlar el cálculo. No utilice ninguna
función de la biblioteca de matemáticas.
#include <iostream>
using namespace std;
int main()
{
int base;
int exp;
int resultado = 1;
cout << "Base entera: ";
cin >> base;
cout << "Exponente entero: ";
cin >> exp;
for (int i = 1 ; i <= exp ; ++i)
resultado *= base;
cout << base << "^" << exp << " = " << resultado << endl;
return 0;
}
7. (Hipotenusa) Defina una función llamada hipotenusa que calcule la
longitud de la hipotenusa de un triángulo recto,
cuando se proporcionen las longitudes de los otros dos lados. Use
esta función en un programa para determinar la longitud de
la hipotenusa para cada uno de los triángulos que se muestran a
continuación. La función debe recibir dos argumentos double
y devolver la hipotenusa como double.
Triángulo Lado 1 Lado 2
1 3.0 4.0
2 5.0 12.0
3 8.0 15.0
#include <iostream>
#include <math.h>
using namespace std;
double hipotenusa(double x);
int main()
{
double lado1;
double lado2;
double hipotenusa1;
double hipotenusa2;
double hipotenusa3;
cout<< " ttnTriangulo "<< " tLado 1 "<< " Lado 2 "<<"
Hipotenusan ";
cout<< "1"<<"tt3.0"<<" t4.0 "<<"t"<<hipotenusa1<<"n";
cout<< " 2 "<<"tt5.0 "<<" t12.0 "<<"t"<<hipotenusa2<<"n";
cout<< " 3 "<<"tt8.0"<<" t15.0 "<<"t"<<hipotenusa3<<"n";
hipotenusa1=sqrt(pow(3.0,2)+pow(4.0,2));
hipotenusa2=pow(5.0*5.0+12.0*12.0,1/2);
hipotenusa3=pow(8.0*8.0+15.0*15.0,1/2);
}
8. Escriba una función llamada multiple que determine, para un par de
enteros, si el segundo entero es múltiplo del
primero. La función debe tomar dos argumentos enteros y devolver true
si el segundo es múltiplo del primero, y false en caso
contrario. Use esta función en un programa que reciba como entrada
una serie de pares de enteros.
#include <iostream>
#include <iostream>
#include <conio.h>
using namespace std;
bool funcion(int a, int b)
{
if(b % a == 0)
{
return true;
}
else
{
return false;
}
}
int main()
{
if(funcion(1, 3))
{
cout << "Si son multiplos!";
}
else
{
cout << "No son multiplos!";
}
return 0;
}

More Related Content

Featured

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Featured (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Docuemnto 6

  • 1. TRABAJO ENCARGADO N° 2 Lenguaje de Programación ESTUDIANTE: Rene Suaña Coila SEMESTRE: III 1. Muestre el valor de x después de ejecutar cada una de las siguientes instrucciones: a) x =fabs( 7.5 ); b) x = floor( 7.5 ); c) x = fabs( 0.0 ); d) x = ceil( 0.0 ); e) x = fabs( -6.4 ); f) x = ceil( -6.4 ); g) x =ceil( -fabs( -8 + floor( -5.5 ) ) ) #include <iostream> #include <math.h> using namespace std; double valor1 (double x) { cout<< " El valor de x=fabs(7.5) "<< " es "; return fabs (x); } int valor2 (double x) { cout << " El valor de x = floor( 7.5 ) "<< " es "; return floor(x); } int valor3 (double x) { cout<< " EL valor de x = fabs( 0.0 ) "<< " es "; return fabs (x); } int valor4 (double x) { cout << " El valor de x = ceil( 0.0 ) " << " es: "; return ceil(x); } int valor5 (double x) { cout<< " EL valor de x = fabs( -6.4 ) "<< " es: "; return fabs (x); } int valor6 (double x) { cout << " El valor de x = ceil( -6.4 ) "<< " es: "; return ceil(x); } int valor7 (double x) { cout<< " El valor de x =ceil( -fabs( -8 + floor( -5.5 ) ) ) "<<" es: "; return ceil(-fabs(-8+floor(x))); } int main () { cout<<valor1(7.5)<<endl; cout<<valor2(7.5)<<endl; cout<<valor3(0.0)<<endl; cout<<valor4(0.0)<<endl; cout<<valor5(-6.4)<<endl; cout<<valor6(-6.4)<<endl; cout<<valor7(-5.5)<<endl; }
  • 2. 2. Un estacionamiento cobra una cuota mínima de $2.00 por estacionarse hasta tres horas. El estacionamiento cobra $0.50 adicional por cada hora o fracción que se pase de tres horas. El cargo máximo para cualquier periodo dado de 24 horas es de $10.00. Suponga que ningún auto se estaciona durante más de 24 horas a la vez. Escriba un programa que calcule y muestre los cargos por estacionamiento para cada uno de tres clientes que estacionaron su auto ayer en este estacionamiento. Debe Introducir las horas de estacionamiento para cada cliente. El programa debe imprimir los resultados en un formato tabular Ordenado, debe calcular e imprimir el total de los recibos de ayer. El programa debe utilizar la función calcularCargos para Determinar el cargo para cada cliente. Sus resultados deben aparecer en el siguiente formato: Auto Horas Cargo 1 1.5 2.00 2 4.0 2.50 3 24.0 10.00 TOTAL 29.50 14.50 #include <iostream> using namespace std; float calcularCargo(float x); int main () { float horas1; float horas2; float horas3; float cargo1; float cargo2; float cargo3; float totalhoras; float totalcargo; cout<< " Horas del Auto 1: "; cin>>horas1; cout<< " Horas del Auto 2: "; cin>>horas2; cout<< " Horas del Auto 3: "; cin>>horas3; cout<< " nAuto " << " Horas "<< " Cargon "; cout<<"1"; cargo1=calcularCargo(horas1); cout<<"n 2"; cargo2=calcularCargo(horas2); cout<<"n 3"; cargo3=calcularCargo(horas3); totalhoras = horas1 + horas2 + horas3; totalcargo = cargo1 + cargo2 + cargo3; cout<< " nTotal "<<"t"<<totalhoras<<"t"<<totalcargo; return 0; } float calcularCargo(float x) { cout<<"t"<<x; if((float)x <=3) {
  • 3. cout<<"t"<<2.0; return 2.0; } else { if((int)x == 24) { cout<<"t"<<10.0; return 10.0; } else { cout<<"t"<<(((float) x-3)*0.5)+2; return (((float)x-3)*0.5)+2; } } } 3. Una aplicación de la función floor es redondear un valor al siguiente entero. La instrucción y = floor( x + .5 ); redondea el número x al entero más cercano y asigna el resultado a y. Escriba un programa que lea varios números y que utilice la instrucción anterior para redondear cada uno de los números a su entero más cercano. Para cada número procesado, muestre tanto el número original como el redondeado. #include <iostream> #include <math.h> using namespace std; double EnteroCercano(double x); int main () { double (x); cout<< " Ingrese un numero: "; cin>>x; cout<<x<<"t"; cout<<EnteroCercano(x); } double EnteroCercano(double x) { return floor(x+0.5); }
  • 4. 4. La función floor puede utilizarse para redondear un número hasta un lugar decimal específi co. La instrucción y = floor( x * 10 + .5 ) / 10; redondea x en la posición de las décimas (es decir, la primera posición a la derecha del punto decimal). La instrucción y = floor( x * 100 + 0.5 ) / 100; redondea x en la posición de las centésimas (es decir, la segunda posición a la derecha del punto decimal). Escriba un programa que defi na cuatro funciones para redondear un número x en varias formas: a) redondearAEntero( numero ) b) redondearADecimas( numero ) c) redondearACentesimas( numero ) d) redondearAMilesimas( numero ) Para cada valor leído, su programa debe imprimir el valor original, el número redondeado al entero más cercano, el número redondeado a la décima más cercana, el número redondeado a la centésima más cercana y el número redondeado a la milésima más cercana. #include <iostream> #include <math.h> using namespace std; double redondearAEntero(double x) { return floor((x+0.5)); } double redondearADecimas(double x) { return floor((x*10+0.5)/10); } double redondearACentesimas (double x) { return floor((x*100+0.5)/100); } double redondearAMilesimas (double x) { return floor((x*1000+0.5)/1000); } int main() { double numero; cout<< " Ingrese un numero: "; cin>>numero; cout<<redondearAEntero(numero)<<" Entero "<<endl; cout<<redondearADecimas(numero)<<" Decimas "<<endl; cout<<redondearACentesimas(numero)<< " Centesimas "<<endl; cout<<redondearAMilesimas(numero)<< " Milesimas "<<endl; }
  • 5. 5. Escriba instrucciones que asignen enteros aleatorios a la variable n en los siguientes rangos: a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤ n ≤ 1112 e) –1 ≤ n ≤ 1 f) –3 ≤ n ≤ 11 #include <ostream> #include <cstdlib> #include <iomanip> using namespace std; int main() { cout<< " a: "; cout<<setw(1)<<(1+rand()%2)<<endl; cout<< " b: "; cout<<setw(1)<<(1+rand()%100)<<endl; cout<< " c: "; cout<<setw(1)<<(0+rand()%9)<<endl; cout<< " d: "; cout<<setw(1)<<(1000+rand()%1112)<<endl; cout<< " e: "; cout<<setw(1)<<(-1+rand()%1)<<endl; cout<< " f: "; cout<<setw(1)<<(-3+rand()%11)<<endl; } 6. Escriba una función llamada enteroPotencia( base, exponente ) que devuelva el valor de base exponente Por ejemplo, enteroPotencia( 3, 4 ) = 3 * 3 * 3 * 3. Suponga que exponente es un entero positivo distinto de cero y que base es un entero. La función enteroPotencia debe utilizar un ciclo for o while para controlar el cálculo. No utilice ninguna función de la biblioteca de matemáticas. #include <iostream> using namespace std; int main() { int base; int exp; int resultado = 1; cout << "Base entera: "; cin >> base; cout << "Exponente entero: "; cin >> exp; for (int i = 1 ; i <= exp ; ++i) resultado *= base; cout << base << "^" << exp << " = " << resultado << endl; return 0; }
  • 6. 7. (Hipotenusa) Defina una función llamada hipotenusa que calcule la longitud de la hipotenusa de un triángulo recto, cuando se proporcionen las longitudes de los otros dos lados. Use esta función en un programa para determinar la longitud de la hipotenusa para cada uno de los triángulos que se muestran a continuación. La función debe recibir dos argumentos double y devolver la hipotenusa como double. Triángulo Lado 1 Lado 2 1 3.0 4.0 2 5.0 12.0 3 8.0 15.0 #include <iostream> #include <math.h> using namespace std; double hipotenusa(double x); int main() { double lado1; double lado2; double hipotenusa1; double hipotenusa2; double hipotenusa3; cout<< " ttnTriangulo "<< " tLado 1 "<< " Lado 2 "<<" Hipotenusan "; cout<< "1"<<"tt3.0"<<" t4.0 "<<"t"<<hipotenusa1<<"n"; cout<< " 2 "<<"tt5.0 "<<" t12.0 "<<"t"<<hipotenusa2<<"n"; cout<< " 3 "<<"tt8.0"<<" t15.0 "<<"t"<<hipotenusa3<<"n"; hipotenusa1=sqrt(pow(3.0,2)+pow(4.0,2)); hipotenusa2=pow(5.0*5.0+12.0*12.0,1/2); hipotenusa3=pow(8.0*8.0+15.0*15.0,1/2); } 8. Escriba una función llamada multiple que determine, para un par de enteros, si el segundo entero es múltiplo del primero. La función debe tomar dos argumentos enteros y devolver true si el segundo es múltiplo del primero, y false en caso contrario. Use esta función en un programa que reciba como entrada una serie de pares de enteros. #include <iostream> #include <iostream> #include <conio.h> using namespace std; bool funcion(int a, int b) { if(b % a == 0) { return true; } else { return false; } } int main()
  • 7. { if(funcion(1, 3)) { cout << "Si son multiplos!"; } else { cout << "No son multiplos!"; } return 0; }