#WSQ08 #TC1017

Se usan funciones para tener estructurado y limpio el programa. Se definen las funciones como int y se regresan para obtener ese valor y luego se imprime para mostrarlo. Las funciones son importantes ya que completan al main y hacen que el programa este compuesto de pequeñas funciones. 

<iostream>

using namespace std;

 

int suma_numeros (int number1,int number2)

{ int suma;

 

  suma= number1 + number2;

  cout << “The sum of the numbers is: “<< suma << endl;

  return suma;

}

 

int diferencia_numeros (int number1,int number2)

{ int diferencia;

 

  diferencia= number1 – number2;

  cout << “The difference of the numbers is: “<< diferencia << endl;

  return diferencia;

}

int division_numeros (int number1,int number2)

{ int division;

 

  division= number1 / number2;

  cout<< “The result of the division is: “<< division << endl;

  return division;

}

int producto_numeros (int number1,int number2)

{ int producto;

 

  producto= number1 % number2;

  cout << “The remainder of the division is: “<< producto << endl;

  return producto;

}

 

 

int main ()

{

 

  int number1, number2;

  cout << “Give me two numbers: ” << endl;

 

  cout << “First number: “<< endl;

  cin >> number1;

  cout << “Second number: “<< endl;

  cin >> number2;

 

  suma_numeros(number1, number2);

  diferencia_numeros(number1, number2);

  division_numeros (number1, number2);

  producto_numeros (number1, number2);

  return 0;

}

 

CC BY 4.0 #WSQ08 #TC1017 by Pablo Guerra is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.