Sei sulla pagina 1di 15

/* ESTRUCTURA DE UN PROGRAMA EN VISUAL C++*/ //CABECERA #include <iostream> using namespace std; //DECLARACIONES GLOBALES DE VARIABLES Y FUNCIONES //Variables

float PV,IGV_P,VV,IGV; // Declaracin de Funciones e Implementacin //PROGRAMA PRINCIPAL void main (void) { //CUERPO DEL PROGRAMA //ENTRADA cout<<"Ingrese Valor de Venta: "; cin>>VV; cout<<"Ingrese IGV_p:"; cin>>IGV; //PROCESO IGV_P=VV*IGV/100; PV=VV+IGV_P; //SALIDA cout<<"\n"; cout<<"IGV: "<<IGV_P<<"\n"; cout<<"PRECIO DE VENTA: "<<PV<<"\n"; cin>>PV; }

/* ESTRUCTURA DE UN PROGRAMA EN VISUAL C++*/ //CABECERA #include <iostream> #include<math.h> using namespace std; //DECLARACIONES GLOBALES DE VARIABLES Y FUNCIONES //Variables float L1,L2,L3,A,S; // Declaracin de Funciones e Implementacin //PROGRAMA PRINCIPAL void main (void) { //CUERPO DEL PROGRAMA //ENTRADA cout<<"Ingrese L1:"; cin>>L1; cout<<"Ingrese L2:"; cin>>L2; cout<<"Ingrese L3:"; cin>>L3; //PROCESO S=(L1+L2+L3); A=sqrt(S*(S-L1)*(S-L2)*(S-L3)); //SALIDA cout<<"\n"; cout<<"A: "<<A<<"\n"; cin>>A; }

/* ESTRUCTURA DE UN PROGRAMA EN VISUAL C++*/ //CABECERA #include <iostream> #include<math.h> using namespace std; //DECLARACIONES GLOBALES DE VARIABLES Y FUNCIONES //Variables float R,B,E; // Declaracin de Funciones e Implementacin //PROGRAMA PRINCIPAL void main (void) { //CUERPO DEL PROGRAMA //ENTRADA cout<<"Ingrese la base:"; cin>>B; cout<<"Ingrese exponente:"; cin>>E;

//PROCESO R=pow(B,E); //SALIDA cout<<"\n El resultado es:"<<R<<end1<<; cin>>B; }

1. Devolver un numero de 5 cifras al revs

#include <iostream> using namespace std; int main() { int n,a,b,c,d,e,respuesta; cout << "Ingrese un Numero de 5 cifras: " << "\n"; cin >> n; e = ((((n%10000)%1000)%100)%10); d = (((n%10000)%1000)%100)-e; c = ((n%10000)%1000)-(e+d); b = (n%10000)-(e+d+c); a = n -(e+d+c+b); respuesta = e*10000 + d*100 + c + b/100 + a/10000 ; cout << respuesta; return 1; }

2. Dada una cantidad de segundos, hallar el numero de Horas:Minutos:Segundos #include <iostream> using namespace std; int main() { int n, horas, minutos, segundos,e ; cout <<"Ingrese un Numero" << "\n"; cin >> n; horas = n/3600; minutos = (n%3600)/60; segundos = (n%3600)&60; cout<<horas<<":"<<minutos<<":"<<segundos; }

#include<iostream> using namespace std; int a,b; void main (void) { cout<<"ingrese a,b"; cin>>a; cin>>b; if(a==b) cout<<"a es igual a b"; else { if(a>b) cout<< "a es mayor que b"; else cout<<" b es mayor que a"; } cin>>a; }

#include<iostream> using namespace std; int a,b; void main (void) { cout<<"ingrese a,b"; cin>>a; cin>>b; switch (a) { case b: cout<<" a es igual a b"; break default if(a>b) cout<<" a es mayor q b"; if(a<b) cout<<b es menor q a; break; } } cin>>a;

#include<iostream> using namespace std; int a; void main (void) { cout<<"ingrese a \n"; cin>>a; switch (a) { case 0: cout<<" a es igual a b"; break; default if(a>0) cout<<" a es positivo"; if(a<0) cout<<" a es negativo" break; } } cin>>a;

#include<iostream> using namespace std; int a; void main (void) { cout<<"MENU DE OPCIONES \n, 1.OPCION 1 \n, 2.OPCION 2 \n, 3.OPCION 3 \n, 4.OPCION \n, 5.OPCION \n, INGRESE SELECCION \n "; cin>>a; }

#include<iostream> using namespace std; int t; void main (void) { cout<<"ingrese t \n"; cin>>t; if((t>0)&&(t<15)) cout<<"t es clima frio"; if((t>15)&&(t<20.1)) cout<< "a es clima templado"; if((t>20.1)&&(t<28)) cout<<" t es buen clima"; if(t>28) cout<<" t uff q calor"; cin>>t; }

#include<iostream> using namespace std; int a,b,c,x; void main (void) { cout<<"1.ingresar tres numeros y ordenarlos ascendentemente\n"; cout<<"2.ingresar tres numeros y ordenarlos ascendentemente\n"; cout<<"3.salir del programa\n"; cout<<"ingrese una opcion"; cin>>x; switch (x) { case 0: cout<<" a es igual a b"; break default if(a>0) cout<<" a es positivo"; if(a<0) cout<<" a es negativo" break; } } cin>>a;

cout<<"\ingrese a"; cin>>a; cout<<"\ingrese b" cin>>b; cout<<"\ingrese c"; cin>>c; if((a>b)&&(a<c)) cout<<b<<" "<<a<<" "<<c; if((b>a)&&(b<c)) cout<<a<<" "<<b<<" "<<c; if((c>a)&&(c<b)) cout<<a<<" "<<c<<" "<<b; cin>>a; }

#include<iostream> using namespace std; int a,b,c,x; void main (void) { cout<<"1.ingresar tres numeros y ordenarlos ascendentemente\n"; cout<<"2.ingresar tres numeros y ordenarlos ascendentemente\n"; cout<<"3.salir del programa\n"; cout<<"ingrese una opcion"; cin>>x; switch (x) { case 1: cout<<"\ingrese a"; cin>>a; cout<<"\ingrese b" cin>>b; cout<<"\ingrese c"; cin>>c; if((a>b)&&(a<c)) cout<<b<<" "<<a<<" "<<c; if((b>a)&&(b<c)) cout<<a<<" "<<b<<" "<<c; if((c>a)&&(c<b)) cout<<a<<" "<<c<<" "<<b; def cin>>a; }

EJERCICIOS 1: #include<iostream> using namespace std; int a,b,c; void main (void) { cout<<"ingrese a"; cin>>a; cout<<"ingrese b"; cin>>b; cout<<"ingrese c"; cin>>c; if((a>b)&&(a<c)) cout<<b<<" "<<a<<" "<<c; if((b>a)&&(b<c)) cout<<a<<" "<<b<<" "<<c; if((c>a)&&(c<b)) cout<<a<<" "<<c<<" "<<b; cin>>a; } 2: descendentemente #include<iostream> using namespace std; int a,b,c; void main (void) { cout<<"ingrese a"; cin>>a; cout<<"ingrese b"; cin>>b; cout<<"ingrese c"; cin>>c; if((a>b)&&(a<c)) cout<<c<<" "<<a<<" "<<b; if((b>c)&&(b<a)) cout<<a<<" "<<b<<" "<<c; if((c>a)&&(c<b)) cout<<b<<" "<<c<<" "<<a; cin>>a; }

Ejercicio 02: Elabore el diagrama de flujo y programa para hallar suma de N primeros nmeros naturales positivos.

#include <iostream> #include <conio.h> using namespace std; void main (void) { int i,n,s=0;//inicializando la variable cout<<"ingrese un numero:";cin>>n; i=1; while(i<=n) { s=s+i; i=i+1; } cout<<"\n"; cout<<"suma:"<<s<<"\n";

getch(); }

Ejercicio 04: Elabore el pseudocdigo y programa para qu dado un grupo de nmeros naturales positivos, calcule e imprima el cuadrado y cubo de estos nmeros.

#include <iostream>

#include <math.h> using namespace std; void main () { double N; cout<<endl<<"INGRESE UN NUMERO N:";cin>>N; cout<<"\n"; while(N>0) { cout<<"EL CUBO ES:"<<"\t"<<(pow(N,3))<<"\n"<<"EL CUADRADO ES:"<<"\t"<<(pow(N,2)); cout<<"\n"; cout<<endl<<"INGRESE UN NUMERO N:";cin>>N; cout<<"\n"; }}

Disee un diagrama de flujo y programa para calcular el digito mayor y el digito menor de un nmero ingresado por teclado.

#include <iostream> #include <conio.h> #include <math.h> using namespace std; void main() { long int Num,n,Inv; int digmenor,digmayor,digito,K; char Rpta; do { digmenor=9; digmayor=0; cout<<"INGRESE UN NUMERO ENTERO: ";cin>>Num; n=Num; Inv=0; K=0;//inicializando variables a 0 cout<<"\nLOS DIGITOS DEL NUMERO DADO SON: "; //do anidados

do {(digito=n%10); cout<<digito<<" "; if (digito<digmenor) {digmenor=digito;} if (digito>digmayor) {digmayor=digito;}

n=(n-digito)/10; //N=N/10; Inv=Inv*10+digito; K=K+1; } while (n>0); cout<<"\nEL DIGITO MENOR ES: "<<digmenor<<"\t"<<"Y EL MAYOR ES: "<<digmayor<<""; if (Num==Inv) cout<<"\nNO SEAS VIVO EL NUMERO DADO ES CAPICUA";//numero capicua aquel que se lee igual de izquierda a derecha y viceversa else cout<<"\nELNUMERO DADO NO ES CAPICUA"; cout<<"\nEL NUMERO TIENE "<<K<<" digitos"; cout<<"\n\nDESEA CONTINUAR (S/N): "; cin>>Rpta;} while (Rpta != 'N' && Rpta != 'n' ); getch();

Potrebbero piacerti anche