Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

G

C++ suma de dos nmeros enteros

Codigo fuente:
#include <iostream.h> main() {int a,b,suma; cout<<"\n ingrese numero a:"; cin>>a; cout<<"\n ingrese numero b:"; cin>>b; suma=a+b; cout<<"\n la suma de "<<a<<"+"<<b<<" es:"<<suma; return 0; }

Como sumar,dividir,restar,multiplicar
#include <iostream> #include <cmath> #include <cstdlib> using namespace std; double Sumar(double,double); double Restar(double,double); double Multiplicar(double,double); double Dividir(double,double); // - Creado por KarmaPolice int main() { cout << "-------- Calculadora C++ --------" << endl; cout << "---------------------------------" << endl; double val1; cout << "Introduce el primer valor: "; cin >> val1; double val2; cout << "Introduce el segundo valor: ";

cin >> val2; cout << "---------------------------------" << endl; int operador; cout << "Sumar (1), Restar (2), Multiplicar (3) o Dividir (4)?: "; cin >> operador; switch(operador) { case 1: cout << "\n"; cout << ">>>>>--cout << "\n"; break; case 2: cout << "\n"; cout << ">>>>>--cout << "\n"; break; case 3: cout << "\n"; cout << ">>>>>--cout << "\n"; break; case 4: cout << "\n"; cout << ">>>>>--cout << "\n"; break; } system("pause"); return 0; } double Sumar(double x,double y) { return x + y; } double Restar(double x,double y) { return x - y; } double Multiplicar(double x,double y) { return x * y; } double Dividir(double x,double y) { return x / y; }

" << Sumar(val1,val2) << " ---<<<<<" << endl;

" << Restar(val1,val2) << " ---<<<<<" << endl;

" << Multiplicar(val1,val2) << " ---<<<<<" << endl;

" << Dividir(val1,val2) << " ---<<<<<" << endl;

You might also like