C++
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include<cmath>
using namespace std;
int suma (int A, int B){
int SU;
SU = A + B;
}
int mayme (int N1, int N2){
int numa;
if(N1 > N2){
numa = N1;
}else{
numa = N2;
}
}
int mayme3 (int N11, int N22, int N33){
int numa3;
if(N11 > N22 && N11 > N33){
numa3 = N11;
}else if(N22 > N11 && N22 > N33){
numa3 = N22;
}else {
numa3 = N33;
}
}
int hipo (int cat1, int cat2){
double numa4;
numa4 = sqrt(pow(cat1,2.0)+ pow(cat2,2.0));
}
int cienle(int bc, int r, int n){
bc = 0;
r = 0;
while(bc <= 100){
cout<<"Ingrese un numero: "<<endl;
cin>>n;
r = r + n;
bc = bc + 1;
}
return r;
}
int cienle6(int rr, int ir, int nr, int br){
rr = 0;
ir = 1;
while(ir <= br){
cout<<"Ingrese un numero: "<<endl;
cin>>nr;
rr = rr + nr;
ir = ir + 1;
}
return rr;
}
void e7 (int ip){
cout << "*****" << ip << "******" << endl;
int e8im (int ii, int si, int ni){
int numa8;
si = 0;
for (ii = 1; ii <= ni; ii++){
si = si + (2*ii - 1);
}
numa8 = si;
return si;
int e8pa(int iip, int sip, int nii){
sip =0;
int numa82;
for (iip = 0; iip <= nii; iip = iip + 2){
sip = sip + iip;
}
numa82 = sip;
return sip;
}
int e8pp(int iipp, int sipp, int nip){
sipp = 0;
int numa83;
for (iipp = 0; iipp <= nip;
iipp++){
if(iipp % 3 == nip){
numa83 = sipp;
sipp = 3 + iipp;
}else{
sipp = 3 + iipp;
}
}
return sipp;
}
void e9 (int h, int m, int s){
cout << h << ":" << m << ":" << s << endl;
void e10(int par, int impar, int nia, int ipa, int niar){
par= 0;
impar = 1;
for (ipa = 0; ipa < nia; ipa++){
cout << "Ingrese un numero : " << endl;
cin >> niar;
if (niar%2== 0){
par += niar;
}else{
impar *= niar;
}
}
}
int e11(int cont, int nn, int max, int num){
int n11;
for(cont = 0; cont < nn; cont++){
cout << "Ingrese un numero: " << endl;
cin >> num;
if(num > max){
max= num;
}
}
n11 = max;
return n11;
}
int e12(int anio){
bool n12;
if(anio%4 == 0 && anio%400 == 0){
n12 = 1;
}else{
n12 = 0;
}
return n12;
}
int e13(int id, int n, int sd, int nd){
for (id=1; id<n; id++) {
if (nd % id == 0)
sd += id;
}
return sd;
int e14(float pago, float sumc, float vuelt, float ca){
if(pago >= sumc){
vuelt = pago - sumc;
ca = pago + ca;
ca = ca - vuelt;
cout <<"Cuesta: " << sumc << " Pago: "<< pago <<" Vuelto: " << vuelt << "
En caja hay: " << ca << endl;
}else{
cout<<"Pago insuficiente"<< endl;
}
}
int main(int argc, char** argv) {
int menu, menu2;
do{
cout << "Ingrese el numero del programa que desea ejecutar: "<<endl;
cout << "1. Suma de dos numeros"<<endl;
cout << "2. Leer 2 numeros diferentes y nos diga cuál es el mayor de los 3 numeros"<<endl;
cout << "3. Almacenen 3 numeros en 3 variables A, B y C. El diagrama debe decidir cual es el mayor
y cual es el menor"<<endl;
cout << "4. Calcule la hipotenusa de un triangulo rectangulo, conocidos su dos catetos"<<endl;
cout << "5. Sumar 100 numeros leidos por teclado"<<endl;
cout << "6. Sumar N numeros. El valor de N se debe leer previamente por teclado"<<endl;
cout << "7. Permita escribir los 100 primeros pares"<<endl;
cout << "8. Sumar los N primeros impares. Realizar despues uno que haga lo mismo con los pares y
otro con los multiplos de 3"<<endl;
cout << "9. Simule un reloj"<<endl;
cout << "10. Lea N numeros, calcule y escriba la suma de los pares y el producto de los
impares"<<endl;
cout << "11. Calcular el maximo de N numeros leidos desde teclado"<<endl;
cout << "12. Un año es bisiesto si es multiplo de 4, exceptuando los multiplos de 100"<<endl;
cout << "13. Dados dos numeros enteros positivos N y D"<<endl;
cout << "14. Simule una caja registradora"<<endl;
cout << "15. Salir"<<endl;
cout <<">> "; cin >> menu;
switch(menu){
case 1:
cout<<"EJERCICIO 1 " << endl;
int a, b, total;
cout<<"Ingrese un numero: "; cin >> a;
cout<<"Ingrese un numero: "; cin >> b;
total = suma(a, b);
cout << total << endl;
cout<<" "<< endl;
break;
case 2:
cout<<"EJERCICIO 2 " << endl;
int n1, n2, total2;
cout<<"Ingrese un numero: "; cin >> n1;
cout<<"Ingrese un numero: "; cin >> n2;
total2 = mayme(n1, n2);
cout << "El mayor es: " << total2 << endl;
cout<<" "<< endl;
break;
case 3:
cout<<"EJERCICIO 3 " << endl;
int n11, n22, n33, total3;
cout<<"Ingrese un numero: "; cin >> n11;
cout<<"Ingrese un numero: "; cin >> n22;
cout<<"Ingrese un numero: "; cin >> n33;
total3 = mayme3(n11, n22, n33);
cout << "El mayor es: " << total3 << endl;
cout<<" "<< endl;
break;
case 4:
cout<<"EJERCICIO 4 " << endl;
double cat1, cat2, total4;
cout<<"Cateto 1: "<<endl;
cin>>cat1;
cout<<"Cateto 2: "<<endl;
cin>>cat2;
total4 = hipo(cat1, cat2);
if (cat1 > 0 && cat2 > 0) {
cout << "Hipotenusa: " << total4 << endl;
}else{
cout<<"Los catetos deben ser positivos"<<endl;
}
cout<<" "<< endl;
break;
case 5:
cout<<"EJERCICIO 5 " << endl;
int i, n, bc, r, total5;
total5 = cienle(bc, r, n);
cout << "Resultado total " << total5 << endl;
cout<<" "<< endl;
break;
case 6:
cout<<"EJERCICIO 6 " << endl;
int ir, nr, br, rr, total6;
cout<<"Cuantos numeros desea sumar: "<<endl;
cin>>br;
total6 = cienle6(rr, ir, nr, br);
cout << "Resultado total " << total6 << endl;
cout<<" "<< endl;
break;
case 7:
cout<<"EJERCICIO 7 " << endl;
int total7, ip;
for(ip = 0; ip <= 100; ip = ip + 2){
e7(ip);
}
cout<<" "<< endl;
break;
case 8:
cout<<"EJERCICIO 8 " << endl;
int ii, ni, si, iip, sip, iipp, sipp, total8ip, t8pa, t8pp;
cout << "Ingrese cuantos numeros desea sumar: " << endl;
cin >> ni;
total8ip = e8im(ii, si, ni);
cout << "Resultado total impares " << total8ip << endl;
t8pa = e8pa(iip, sip, ni);
cout << "Resultado total pares " << t8pa << endl;
t8pp = e8pp(iipp, sipp, ni);
cout << "Resultado total primos " << t8pp << endl;
cout<<" "<< endl;
break;
case 9:
cout<<"EJERCICIO 9 " << endl;
int ho, mi, se;
for(ho = 0; ho <= 23; ho++){
for(mi = 0; mi <= 59; mi++){
for(se = 0; se <= 59; se++){
e9(ho, mi, se);
}
}
}
cout<<" "<< endl;
break;
case 10:
cout<<"EJERCICIO 10 " << endl;
int ipa, nia, niar, res, par, impar;
par = 0;
impar = 0;
cout << "Ingrese cuantos numeros desea sumar: " << endl;
cin >> nia;
e10(par, impar, nia, ipa, niar);
cout << "Resultado pares " << par << endl;
cout << "Resultado impares " << impar << endl;
cout<<" "<< endl;
break;
case 11:
cout<<"EJERCICIO 11" << endl;
int nn, max, num, cont, t11;
max = 0;
cout << "Ingrese cuantos valores desea ingresar: " << endl;
cin >> nn;
t11 = e11(cont, nn, max, num);
cout << "El numero maximo es: " << t11<< endl;
cout<<" "<< endl;
break;
case 12:
cout<<"EJERCICIO 12" << endl;
int anio, t12;
cout << "Ingrese un anio: " << endl;
cin >> anio;
t12 = e12(anio);
cout<<t12<< endl;
cout<<" "<< endl;
break;
case 13:
cout<<"EJERCICIO 13" << endl;
int nd,id,sd, t13;
sd = 0;
cout << "Ingrese un numero: "<< endl;
cin >> nd;
t13 = e13(id, n, sd, nd);
if (nd == sd){
cout << "No es un numero perfecto"<< endl;
}else{
cout << "Es un numero perfecto"<< endl;
}
cout<<" "<< endl;
break;
case 14:
cout<<"EJERCICIO 14" << endl;
float ca, sumc, cost, pago, vuelt, t14;
ca = 5000;
sumc = 0;
cout << "Ingresar costo del producto: "<< endl;
cin >> cost;
sumc = cost;
cout << "Ingresar pago: "<< endl;
cin >> pago;
e14(pago, sumc, vuelt, ca);
cout<<" "<< endl;
break;
} while (menu != 15);
return 0;
}