Programas Básicos en Borland c++
Bueno aquie teneis unos programas basicos que los realize a modo de practica utilizando borland c++ espero que les sea de utilidad ya de esta manera espero contribuir a los que recien nos iniciamos en este hermoso lenguaje de programacion c++...... en esta sección veremso estructuras de condicion multiple.
Estructuras Secuencial Multiple Segun sea Calculadora en c++ /*Construir una calculadora que permita ingresar 2 numeros y un operador, luego debera efectuar la operacion indicada (+= suma, -= resta, *= multiplicacion, /= Division y #= Potencia).*/ #include<iostream.h> #include<conio.h> #include<stdlib.h> #include<math.h> float n1, n2; char op; double r; void main(){ cout<<" CALCULADORA C++ "; cout<<"\n\r ---------------"; cout<<"\n\r Ingrese el primer operando "; cin>>n1; cout<<"\n\r Ingrese el operador +, -, *, /, # \n"; cin>>op; cout<<"\n\r Ingrese un segundo operando "; cin>>n2; switch(op){ case'+':r=n1+n2; break; case'-':r=n1-n2; break; case'*':r=n1*n2; break; case'/':r=n1/n2; break; case'#':r=pow(n1,n2); break; default:cout<<"\n\r operador no definido"; exit(1); }cout<<"\n\r el resultado es " <<r; getch(); }
Tu signo Zodiacal /*ingrese dia y mes de nacimiento, luego se debe determinar su signo sodiacal*/ #include<iostream.h> #include<conio.h> int dia, mes; void main(){ cout<<" TU SIGNO ZODIACAL "; cout<<"\n\r ---------------"; cout<<"\n\r Ingrese el Dia y mes de nacimiento "; cin>>dia>>mes; switch(mes){ case 1: if(dia<21) cout<<"CAPRICORNIO"; else cout<<"ACUARIO"; break; case 2: if(dia<20) cout<<"ACUARIO"; else cout<<"PICIS"; break; case 3: if(dia<21) cout<<"PICIS"; else cout<<"ARIES"; break; case 4: if(dia<21) cout<<"ARIES"; else cout<<"TAURO"; break; case 5: if(dia<21) cout<<"TAURO"; else cout<<"GEMINIS"; break; case 6: if(dia<22) cout<<"GEMINIS"; else cout<<"CANCER"; break; case 7: if(dia<23) cout<<"CANCER"; else cout<<"LEO"; break; case 8: if(dia<23) cout<<"LEO"; else cout<<"VIRGO"; break; case 9: if(dia<23) cout<<"VIRGO"; else cout<<"LIBRA"; break; case 10: if(dia<23) cout<<"LIBRA"; else cout<<"ESCORPIO"; break; case 11: if(dia<22) cout<<"ESCORPIO"; else cout<<"SAGITARIO"; break; case 12: if(dia<22) cout<<"SAGITARIO"; else cout<<"CAPRICORNIO"; break; default:cout<<"\n\r Mes y Dia son incorrectos"; } getch(); }
Converion a romanos /*ingrese un numero arabigo menmor a 4000 y convertirlo a romano*/ #include<iostream.h> #include<conio.h> int n, u, d, c, m; void main(){ cout<<" CONVERSION DE ARABIGOS A ROMANOS "; cout<<"\n\r -----------------------------"; cout<<"\n\r Ingrese un numero entre 0 y 3999 \n\r"; cin>>n; u=n%10; n=n/10; d=n%10; n=n/10; c=n%10; n/10; m=n%10; switch(m){ case 1: cout<<"M"; break; case 2: cout<<"MM"; break; case 3: cout<<"MMM"; break; } switch(c){ case 1: cout<<"C"; break; case 2: cout<<"CC"; break; case 3: cout<<"CCC"; break; case 4: cout<<"CD"; break; case 5: cout<<"D"; break; case 6: cout<<"DC"; break; case 7: cout<<"DCC"; break; case 8: cout<<"DCCC"; break; case 9: cout<<"CM"; break; } switch(d){ case 1: cout<<"X"; break; case 2: cout<<"XX"; break; case 3: cout<<"XXX"; break; case 4: cout<<"XL"; break; case 5: cout<<"L"; break; case 6: cout<<"LX"; break; case 7: cout<<"LXX"; break; case 8: cout<<"LXXX"; break; case 9: cout<<"XC"; break; } switch(u){ case 1: cout<<"I"; break; case 2: cout<<"II"; break; case 3: cout<<"III"; break; case 4: cout<<"IV"; break; case 5: cout<<"V"; break; case 6: cout<<"VI"; break; case 7: cout<<"VII"; break; case 8: cout<<"VIII"; break; case 9: cout<<"IX"; break; }
getch(); }
|