Está en la página 1de 23

ALGORITMOS SIMPLE

1. //Dada una cantidad en pesos, obtener la equivalencia en


dólares, asumiendo que la unidad cambiaría es un dato desconocido//
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float PES;
float DOL;
float TC;

cout << "Escriba la cantidad en pesos\n";


cin >> PES;

cout << "Escriba la tasa de cambio (cuantos pesos cuesta un


dolar)\n";
cin >> TC;

DOL = PES/TC;

cout << "la cantidad de dolares que tiene es: " << DOL << endl;

system("pause");
return 0;

2. //Leer un número y escribir el valor absoluto del mismo.//


#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{

float NU;
cout << "ESCRIBA UN NUMERO\n";
cin >> NU;

if (NU<0){
NU = (-1)*NU;
cout << "EL VALOR ABSULUTO DE SU MNERO ES: " << NU <<
endl;
}

else {
cout << "EL VALOR ABSOLUTO DE SU NUMERO ES: " << NU <<
endl;
}

system("pause");
return 0;
}
3. //La presión, el volumen y la temperatura de una masa de aire se
relacionan por la formula: masa = (presión * volumen)/(0.37 *
(temperatura + 460))//
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{

float PR;
float VL;
float TM;
float MS;
int op;

cout << "PARA CALCULAR LA MASA ESCRIBA 1\n"


<< "PARA CALCULAR LA TEMPERATURA ESCRIBA 2\n"
<< "PARA CALCULAR EL VOLUMEN ESCRIBA 3\n"
<< "PARA CALCULAR LA PRESION ESCRIBA 4\n";

cin >> op;

switch(op)
{
case 1:
cout << "PARA CALCULAR LA MASA DE AIRE\n";
cout << "INGRESE LA PRESION ";
cin >> PR;
cout << "INGRESE EL VOLUMEN ";
cin >> VL;
cout << "INGRESE LA TEMPERATURA ";
cin >> TM;

MS=(PR*VL)/(0.37*(TM+460));

cout << "LA MASA ES: " << MS << endl;


break;

case 2:
cout << "PARA CALCULAR LA TEMPERATURA DE AIRE\n";
cout << "INGRESE LA PRESION ";
cin >> PR;
cout << "INGRESE EL VOLUMEN ";
cin >> VL;
cout << "INGRESE LA MASA ";
cin >> MS;

TM=((PR*VL)/(0.37*MS))-460;

cout << "LA TEMPERATURA ES: " << TM << endl;


break;

case 3:
cout << "PARA CALCULAR EL VOLUMEN DE AIRE\n";
cout << "INGRESE LA PRESION ";
cin >> PR;
cout << "INGRESE LA MASA ";
cin >> MS;
cout << "INGRESE LA TEMPERATURA ";
cin >> TM;

VL=(MS*0.37*(TM+460))/PR;

cout << "EL VOLUMEN ES: " << VL << endl;


break;

case 4:
cout << "PARA CALCULAR LA PRESION DE AIRE\n";
cout << "INGRESE LA MASA ";
cin >> MS;
cout << "INGRESE EL VOLUMEN ";
cin >> VL;
cout << "INGRESE LA TEMPERATURA ";
cin >> TM;

PR=(0.37*MS*(TM+460))/VL;

cout << "LA PRESION ES: " << PR << endl;


break;

default:
cout << "EL NUMERO QUE DIGITO NO ES UNA
OPCION\n";
}

system("pause");
return 0;
}

4. //Calcular el número de pulsaciones que una persona debe tener


por cada 10 segundos de ejercicio, si la formula es: Num_
pulsaciones = (220 - edad)/10 //

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int ED;
float NP;
cout << "ESCRIBA SU EDAD\n";
cin >> ED;

NP=(220-ED)/10;

cout << "EL NUEMRO DE PULSACIONES QUE USTED DEBE TENER POR CADA
10 SEGUNDOS DE EJERCICIO ES: " << NP << endl;

system("pause");

return 0;

5. //Calcular el nuevo salario de un obrero si obtuvo un incremento


del 25% sobre su salario anterior.//
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{

float SA;
float NS;

cout << "Salario anterior del obrero\n";


cin >> SA;

NS=(SA*0.25)+SA;

cout << "El nuevo salario del obrero es: $" << NS << endl;

system("pause");

return 0;

6. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float PRE;
float GIN;
float TRA;
float PED;
cout << "ESCRIBA EL PRESUPUESTO ANUAL DEL HOSPITAL\n";
cin >> PRE;

GIN=PRE*0.4;
TRA=PRE*0.3;
PED=PRE*0.3;

cout << "la siguente es la distribucion del presupuesto por


area:\n"
<< "GINECOLOGIA: " << GIN << endl
<<"TRAUMATOLOGIA: " << TRA << endl
<< "PEDIATRIA: " << PED << endl;

system("pause");

return 0;

7. //El dueño de una tienda compra un articulo a un precio


determinado. Obtener el precio en que lo debe vender para obtener
una ganancia del 30%//

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main ()
{
float CM;
float VT;

cout << "A QUE PRECIO COMPRO ESTE ARTICULO\n";


cin >> CM;

VT=(CM*0.3)+CM;

cout << "USTED DEBERIA VENDER ESTE ARTICULO A $" << VT << endl;

system("pause");

return 0;

8. //Todos los lunes, miércoles y viernes, una persona corre la


misma ruta y cronometra los tiempos obtenidos. Determinar el
tiempo promedio que la persona tarda en recorrer la ruta en una
semana cualquiera.//

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float LU;
float MR;
float VR;
float PRO;

cout <<"ESCRIBBA EN MINUTOS EL TIEMPO QUE TARDO EL LUNES ";


cin >> LU;

cout <<"ESCRIBBA EN MINUTOS EL TIEMPO QUE TARDO EL MIERCOLES ";


cin >> MR;

cout <<"ESCRIBBA EN MINUTOS EL TIEMPO QUE TARDO EL VIERNES ";


cin >> VR;

PRO=(LU+MR+VR)/3;

cout <<"EL PROMEDIO DE ESTA SEMANA ES DE: " << PRO << "
MINUTOS." << endl;

system("pause");
return 0;

9. //Tres personas deciden invertir su dinero para fundar una


empresa. Cada una de ellas invierte una cantidad distinta. Obtener
el porcentaje que cada quien invierte con respecto a la cantidad
total invertida//

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::string;

int main ()
{
float I1;
float I2;
float I3;
float TOT;
float P1;
float P2;
float P3;
string N1;
string N2;
string N3;

cout <<"ESCRIBA SU NOMBRE " ;


cin >> N1;
cout << N1 << "¿CUANTO INVIRTIO USTED?" << endl;
cin >> I1;

cout << "ESCRIBA SU NOMBRE ";


cin >> N2;
cout << N2 << "¿CUANTO INVIRTIO USTED?" << endl;
cin >> I2;

cout << "ESCRIBA SU NOMBRE ";


cin >> N3;
cout << N3 << "¿CUANTO INVIRTIO USTED?" << endl;
cin >> I3;

TOT=I1+I2+I3;

P1= (I1*100)/TOT;
P2= (I2*100)/TOT;
P3= (I3*100)/TOT;

cout << N1 << " INVIRTIO " << P1 << "%" << endl;
cout << N2 << " INVIRTIO " << P2 << "%" << endl;
cout << N3 << " INVIRTIO " << P3 << "%" << endl;

system("pause");
return 0;

}
10. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float PC;
float TC1;
float TC2;
float TC3;
float PTC;
float PROM;
float PP;
float TP1;
float TP2;
float PTP;
float PI;
float TI1;
float TI2;
float TI3;
float PTI;
float PF1;
float TF1;
float PF2;
float TF2;
float PF3;
float TF3;
float PFF;
float TFF;
float ACU=0;
float PG;
int mat;
for(mat=0; mat <=4; mat++)
{
switch(mat)
{
case 1:
cout << "MATERIA: CALCULO\n";
cout << "nota del parcial de
calculo: ";
cin >> PC;
cout << "nota del primer trabajo de
calculo: ";
cin >> TC1;
cout << "nota del segundo trabajo de
calculo: ";
cin >> TC2;
cout << "nota del tercer trabajo de
calculo: ";
cin >> TC3;

PTC=(TC1+TC2+TC3)/3;
PROM= (PTC*0.1)+(PC*0.9);
cout << "NOTA PROMEDIO DE CALCULO: "
<< PROM << endl;
break;

case 2:
cout << "MATERIA: PROGRAMACION\n";
cout << "nota del parcial de
programacion: ";
cin >> PP;
cout << "nota del primer trabajo de
programacion: ";
cin >> TP1;
cout << "nota del segundo trabajo de
programacion: ";
cin >> TP2;

PTP=(TP1+TP2)/2;
PROM= (PP*0.8)+(PTP*0.2);
cout << "NOTA PROMEDIO DE
PROGRAMACION: " << PROM << endl;
break;

case 3:
cout << "MATERIA: INTROD. A LA
INGENIERIA\n";
cout << "nota del parcial de
introduccion: ";
cin >> PI;
cout << "nota del primer trabajo de
introduccion: ";
cin >> TI1;
cout << "nota del segundo trabajo de
introduccion: ";
cin >> TI2;
cout << "nota del tercer trabajo de
introduccion: ";
cin >> TI3;

PTI=(TI1+TI2+TI3)/3;
PROM=(PI*0.85)+(PTI*0.15);
cout << "NOTA PROMEDIO DE INT. A LA
INGENIERIA: " << PROM << endl;
break;

case 4:
cout << "MATERIA: FISICA\n";
cout << "nota del primer parcial de
fisica: ";
cin >> PF1;
cout << "nota del trabajo del
parcial: ";
cin >> TF1;
cout << "nota del segundo parcial de
fisica: ";
cin >> PF2;
cout << "nota del trabajo del
parcial: ";
cin >> TF2;
cout << "nota del tercer parcial de
fisica: ";
cin >> PF3;
cout << "nota del trabajo del
parcial: ";
cin >> TF3;
cout << "nota del parcial final de
fisica: ";
cin >> PFF;
cout << "nota de los trabajos: ";
cin >> TFF;

PROM= (PF1*0.15)+(TF1*0.05)+
(PF2*0.15)+(TF2*0.05)+(PF3*0.2)+(TF3*0.1)+(PFF*0.2)+(TFF*0.1);
cout << "NOTA PROMEDIO DE FISICA: "
<< PROM << endl;
break;
}

ACU=ACU+PROM;

}
PG=ACU/4;

cout << "EL PROMEDIO GENERAL ES: " << PG << endl;

system("pause");

return 0;

UTILIZANDO EL SI
1. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int NL;
float VL;

cout << "żcuantas llantas desea comprar?";


cin >> NL;

if (NL<5) {
VL=NL*800;
cout << "EL VALOR DE LAS LLANTAS ES: " << VL << endl;
}
if (NL>=5) {
VL=NL*700;
cout << "EL VALOR DE LAS LLANTAS ES: " << VL <<
endl;
}
system("pause");
return 0;
}

2. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int N;
float Co;

cout << "Valor de su compra: ";


cin >> Co;

cout << "Diga un numero al azar: ";


cin >> N;
if (N<50) {
Co=Co-(Co*0.15);
cout << "Ahora el valor de su compra es: " << Co <<
endl;
}
else {
Co=Co-(Co*0.2);
cout << "Ahora el valor de su compra es: " << Co << endl;
}

system("pause");
return 0;

3. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int SE;
int ED;
float PL;

cout << "Escriba 1 (masculino) o 2 (femenino) segun su genero\


n";
cin >> SE;

if (SE==1) {
cout << "Escriba su edad: ";
cin >> ED;
PL= (210- ED)/10;
cout << "El numero de pulsaciones por cada 10
segundos de aerobicos para usted debe ser:\n"
<< PL << endl;
}
if (SE==2) {
cout << "Escriba su edad: ";
cin >> ED;
PL= (220- ED)/10;
cout << "El numero de pulsaciones por cada 10
segundos de aerobicos para usted debe ser:\n"
<< PL << endl;
}

system("pause");
return 0;

4. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float PR;
float CU;

cout << "Escriba el valor del prestamo: ";


cin >> PR;

if (PR<500000) {
CU=PR*0.03;
cout << "La cuota a pagar es: " << CU << endl;
}
else {
CU=PR*0.02;
cout << "La cuota a pagar es: " << CU << endl;
}

system("pause");
return 0;
}

5. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int NM;
float Pr;
float PR;
float TOT;

cout << "ingrese el numero de materias a cursar. ";


cin >> NM;

cout << "Ingrese su promedio del semestre pasado. ";


cin >> Pr;

if (Pr>=9.0 && Pr<10.0) {


PR=NM*30000;
TOT= PR-(PR*0.3);
cout << "El total a pagar por su matricula es: " <<
TOT << endl;
cout << "Se le descontara el costo del internet.\n";
}
if (Pr>0 && Pr<9.0) {
PR=NM*0.10;
TOT= PR;
cout << "El total a pagar por su matricula es: " <<
TOT << endl;
}

system("pause");
return 0;
}

6. #include <iostream>

using std::cout;
using std::cin;
using std::endl;
int main ()
{
float SA;
float VC;
float PC;
float RST;

cout << "Ingrese el valor de la vivienda que va a comprar: $";


cin >> VC;

cout << "Ingrese su salario mensual: $";


cin >> SA;

if (SA<8000) {
PC=VC*0.15;
cout << "La primera cuota que debera pagar es
de: $" << PC << endl;
RST=(VC-PC)/120;
cout << "Usted seguira pagando cuotas mensuales
de: $" << RST << " Hasta que termine de cubrir la deuda" << endl;
}
else {
PC=VC*0.3;
cout << "La primera cuota que debera pagar es de: $" << PC
<< endl;
RST=(VC-PC)/84;
cout << "Usted seguira pagando cuotas mensuales de: $" <<
RST << " Hasta que termine de cubrir la deuda" << endl;
}
system("pause");
return 0;
}

7. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float SA;
float POR;
float SAR;
float REST;

cout << "Escriba su salario bruto: $";


cin >> SA;

cout << "Escriba el portentaje a depositar en SAR: ";


cin >> POR;

SAR=(SA*POR)/100;
REST=SA-SAR;

cout << "EL Dinero que mensualmente sera depositado en SAR es:
$" << SAR << endl;
cout << "El dinero que recibira mensualmente es: $" << REST <<
endl;

system("pause");
return 0;
}

8. #include <iostream>

using namespace std;


int main ()
{
float hipoteca,i,i2;
cout<<"ingrese el monto de la hipoteca"<<endl;
cin>>hipoteca;
cout<<"ingrese el total a invertir por el negocio"<<endl;
cin>>i;

if (hipoteca<1000000)
{
i2=i/2;
cout<<"la inversion de cada socio es de:"<<i2<<"$"<<endl;
}
else
{ i2=(hipoteca-i)/2;
cout<<"la inversion de cada socio es
de:"<<i2<<"$"<<endl; }

return 0;
}
UTILIZANDO EL SI ANIDADO

1. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int LL;
float VL;
float DS;

cout << "Cuantas computadoras desea comprar: ";


cin >> LL;
VL=LL*11000;
if (LL<5)
DS=VL-(VL*0.1);
else if (LL>=5 && LL<10)
DS=VL-(VL*0.2);
else if (LL>=10)
DS=VL-(VL*0.4);

cout << "El valor que se le cobrara es de : $" << DS << endl;

system("pause");
return 0;
}

2. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int CL;
float PL;

cout << "Bienvenido a Ponchadas\n"


<< "Cuantas llantas desea comprar: \n";
cin >> CL;

if (CL<5){
PL=CL*300;
cout << "Cada llanta le cuesta $300\n";
}
else if (CL>=5 && CL<=10) {
PL=CL*250;
cout << "Cada llanta le cuesta $250\n";
}
else if (CL>10){
PL=CL*200;
cout << "Cada llanta le cuesta $200\n";
}

cout << "EL PRECIO TOTAL DE LA COMPRA ES: $" << PL << endl;

system("pause");
return 0;
}

3. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
int PP;
int SP;
int TP;

cout << "RESPONDA CORRECTAMENTE LAS SEGUIENTES PREGUNTAS PARA


GANAR\n"
<< "ESCRIBA 1 SI CREE QUE ES CORRECTO Y 2 SU CREE QUE ES FALSO\
n"
<< ". . \n"
<< "1. ¿Colon descubrio america?";
cin >>PP;
if (PP==1) {
cout << "CORRECTO!\n"
<< "2. La independencia de México fue en el año
1810? \n";
cin >> SP;
if (SP==1) {
cout << "CORRECTO!\n"
<< "3. The Doors fue un grupo de rock americano?\n";
cin >> TP;
if (TP==1) {
cout << "CORRECTO!\n"
<< "GANO!\n";
}
else if (TP==2)
cout << "INCORRECTO!, Perdio\n";
}
else if (SP==2)
cout << "INCORRECTO!, Perdio\n";
}
else if (PP==2)
cout << "INCORRECTO!, Perdio\n";

system("pause");
return 0;
}

4. #ifdef __MSDOS__
    #include <iostream.h>
    #include <stdlib.h>
#else
    #include <iostream>
    #include <cstdlib>
    using namespace std;
#endif

int main (void)
{
    int marca;
    float IVA, descuento, pago, precio_sin_IVA;
    cout << "Ingresa el valor de precio sin IVA: ";
    cin >> precio_sin_IVA;
    cin.get();
    cout << "Selecciona el valor de marca." << endl;
    cout << "\t1.- AOC" << endl;
    cout << "\t2.- Daewoo" << endl;
    cout << "\t3.- Fisher" << endl;
    cout << "\t4.- GE" << endl;
    cout << "\t: ";
    do {
        cin >> marca;
        cin.get();
        if (marca<1||marca>10)
        {
            cout << "Valor incorrecto. Ingr\202salo nuevamente.: ";
        }
    } while (marca<1||marca>10);
    descuento=0;
    if(precio_sin_IVA>2000)
        descuento=descuento+precio_sin_IVA*0.1;
    if(marca==5)
        descuento=descuento+precio_sin_IVA*0.05;
    IVA=(precio_sin_IVA-descuento)*0.16;
    pago=precio_sin_IVA-descuento+IVA;
    cout << "Valor de IVA: " << IVA << endl;
    cout << "Valor de descuento: " << descuento << endl;
    cout << "Valor de pago: " << pago << endl;
    cout << endl;
   
    return 0;
}
5. #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main ()
{
float N1;
float N2;
float N3;

cout << "Ingrese un numero\n";


cin >> N1;
cout << "Ingrese otro numero\n";
cin >> N2;
cout << "Ingrese otro numero\n";
cin >> N3;

if (N1>N2 && N1<N3 || N1<N2 && N1>N3)


cout << "El numero medio es " << N1 << endl;
else if (N2>N1 && N2<N3 || N2<N1 && N2>N3)
cout << "El numero medio es " << N2 << endl;
else if (N3>N1 && N3<N2 || N3<N1 && N3>N2)
cout << "El numero medio es " << N3 << endl;
else
cout << "al menos dos de los numeros son inguales\n";

system("pause");
return 0;
}
UTLIZANDO EL FOR (PARA)

1. #include<stdio.h>

void main()

float peso;

int n=0,j=0,a=0,v=0;

float ninos, jovenes, adultos, viejos;

int x =1, edad;

float promn,promj,proma,promv;

for (x=1; x<=5;x++)

printf("PESO [%d]: ",x);

scanf("%f",&peso);

printf("EDAD [%d]: ",x);

scanf("%d",&edad);
if (edad>0 && edad<=12)

ninos = ninos + peso;

n++;

else if (edad>13 && peso<=29)

jovenes= jovenes + peso;

j++;

else if (edad>30 && edad<=59)

adultos= adultos + peso;

a++;

else

viejos=viejos+ peso;

v++;

promn=ninos/n;

promj=jovenes/j;

proma=adultos/a;

promv=viejos/v;

printf("\tEl promedio de peso de niños es %.2f\n",promn);

printf("\tEl promedio de peso de jovenes es %.2f\n",promj);

printf("\tEl promedio de peso de adultos es %.2f\n",proma);

printf("\tEl promedio de peso de viejos es %.2f\n",promv);

2. #include <iostream>
 
using namespace std;
 
int main()
{
int kilos;
float total, suma = 0.0f;
 
for (int i = 1; i <= 15; i++)
{
cout << "Kilos cliente " << i << ": ";
cin >> kilos;
 
total = 10.0f * kilos;
 
if (kilos > 10)
total -= (10.0f * kilos * 0.15);
 
cout << "\nA pagar: " << total << endl << endl;
 
suma += total;
}
 
cout << "\nTotal ventas: " << suma << endl;
 
return 0;
}

3. #ifdef __MSDOS__
    #include <iostream.h>
    #include <stdlib.h>
#else
    #include <iostream>
    #include <cstdlib>
    using namespace std;
#endif

int main (void)
{
    int i, mas_contaminante, menos_contaminante, puntos_contaminantes;
    float promedio_de_puntos;
    mas_contaminante = 0;
    menos_contaminante = 0;
    promedio_de_puntos = 0;
    for (i=1; i<=25; i++)
    {
        cout << "PROCESO " << i << endl;
        cout << "Ingresa el valor de puntos contaminantes: ";
        cin >> puntos_contaminantes;
        cin.get();
        promedio_de_puntos=promedio_de_puntos+puntos_contaminantes;
        if(i==1||mas_contaminante<puntos_contaminantes)
            mas_contaminante=puntos_contaminantes;
        if(i==1||menos_contaminante>puntos_contaminantes)
            menos_contaminante=puntos_contaminantes;
        cout << endl;
    }
    promedio_de_puntos=promedio_de_puntos/25;
    cout << "Valor de mas contaminante: " << mas_contaminante << endl;
    cout << "Valor de menos contaminante:
" << menos_contaminante << endl;
    cout << "Valor de promedio de puntos:
" << promedio_de_puntos << endl;
    system ("pause");
    return 0;
}

4.

También podría gustarte