Lenguaje de programación
Renzo Leonardo Gerónimo Gonzales
Ciclo:III Seccion:A
SEMANA 09
#include <iostream>
using namespace std;
int main() {
int opcion, n, c, SUMA, tn, ii, jj;
do {
cout << "MENU\n";
cout << "--------------\n";
cout << "1.- Suma de los n primeros terminos\n";
cout << "2.- Suma de los n primeros terminos impares\n";
cout << "3.- TABLA DE MULTIPLICAR\n";
cout << "INGRESE UNA OPCION <> 0 ";
cin >> opcion;
switch (opcion) {
case 1:
cout << "1.- Suma de los n primeros terminos\n\n";
break;
case 2:
cout << "-------------------------------------------\n";
cout << "1.- Suma de los n primeros terminos impares\n";
cout << "-------------------------------------------\n";
cout << "Ingrese el valor del n-simo termino\n ";
cin >> n;
c = 0;
SUMA = 0;
while (c < n) {
c++;
SUMA = SUMA + (2 * c - 1);
cout << "La suma de los " << c << " es : " << SUMA << endl;
}
cout << endl;
break;
case 3:
cout << "\nTabla de multiplicar\n";
cout << "Ingrese el valor hasta donde desea multiplicar: ";
cin >> tn;
for (ii = 1; ii <= tn; ii++) {
cout << "-------------------------------------\n";
cout << "Tabla de Multiplicar de " << ii << "\n";
cout << "-------------------------------------\n";
for (jj = 1; jj <= tn; jj++) {
cout << ii << "x" << jj << " = " << ii * jj << "\n";
}
}
break;
default:
break;
}
} while (opcion != 0);
cout << "asdasd";
return 0;
}
CODIGO 2
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int opcion, n, c, SUMA, tn, ii, jj;
float voltaje, resistencia, corriente;
do {
cout << "MENU\n";
cout << "--------------\n";
cout << "1.- Suma de los n primeros terminos\n";
cout << "2.- Suma de los n primeros terminos impares\n";
cout << "3.- TABLA DE MULTIPLICAR\n";
cout << "4.- Caida de tension\n";
cout << "INGRESE UNA OPCION <> 0 ";
cin >> opcion;
switch (opcion) {
case 1:
cout << "1.- Suma de los n primeros terminos\n\n";
break;
case 2:
cout << "-------------------------------------------\n";
cout << "1.- Suma de los n primeros terminos impares\n";
cout << "-------------------------------------------\n";
cout << "Ingrese el valor del n-simo termino\n ";
cin >> n;
c = 0;
SUMA = 0;
while (c < n) {
c++;
SUMA = SUMA + (2 * c - 1);
cout << "La suma de los " << c << " es : " << SUMA << endl;
}
cout << endl;
break;
case 3:
cout << "\nTabla de multiplicar\n";
cout << "Ingrese el valor hasta donde desea multiplicar: ";
cin >> tn;
for (ii = 1; ii <= tn; ii++) {
cout << "-------------------------------------\n";
cout << "Tabla de Multiplicar de " << ii << "\n";
cout << "-------------------------------------\n";
for (jj = 1; jj <= tn; jj++) {
cout << ii << "x" << jj << " = " << ii * jj << "\n";
}
}
break;
case 4:
cout << "4.- Caida de tension\n";
float i, s, P = 0.075, L = 30, o = 0.85;
for (i = 5; i <= 30; i += 2.5) {
cout << endl << "Cuando la corriente es " << i << " amperios" << endl;
cout << "----------------------------------\n";
for (s = 2.5; s <= 20; s += 0.5) {
cout << "La seccion del cable es " << s << " entonces la caida de tension es " << (P * sqrt(3) * L) / (s * o) << " voltios" << endl;
}
}
break;
}
} while (opcion != 0);
return 0;
}