WSQ05

--Originally published at Rodrigo's Blog

On this program I learned to use functions for the purpose of making it on the long way easier for me to do this kind of programs.

https://github.com/Rodrigovalher98/C-/blob/master/Functions.cpp

#include <iostream>
using namespace std;

int sum (int x, int y)
{
int g;
g = x+y;
return g;
}

int resta (int x, int y)
{
int j;
j = x-y;
return j;
}

int multip (int x, int y)
{
int v;
v = x*y;
return v;
}

int divi (int x, int y)
{
int z;
z = x/y;
return z;
}

int resid (int x,int y)
{
int k;
k = x%y;
return k;
}

int main()
{
int x,y;
cout << ” Enter a number ” << endl;
cin >> x;
cout << ” Enter another number ” << endl;
cin >> y;
cout << ” The sum of the numbers is ” << sum(x,y) << endl;
cout << ” The difference between the numbers is ” << resta(x,y) << endl;
cout << ” The product of the numbers is ” << multip(x,y) << endl;
cout << ” The integer based division between the 2 numbers is ” << divi(x,y) << endl;
cout << ” The remainder of the division between the numbers is ” << resid(x,y) << endl;

return 0;
}


WSQ 04 – Sum of Numbers

--Originally published at Rodrigo&#039;s Blog

On this program I used the internet to get the new formula, and I found a way to make the order of the numbers irrelevant, by this I mean that the number does not have to be bigger at the beginning or ending.

2017-08-29

#include <iostream>
using namespace std;
int main ()
{
int x;
int y;
cout << “Enter 2 integers of whom you would like to get the sum of al the numbers in between” << “\n”;
cout << “Enter the first integer” << “\n”;
cin >> x;
cout <<“Enter the second integer” << “\n”;
cin >> y;
int sum;
if (x<y) {
sum=((((y*(y+1))/2)-((x*(x+1))/2))+x);
cout << “The sum for the 2 numbers is ” << sum << “\n”;}
else if (x>y) {
sum=(((((x)*(x+1))/2)-(((y)*(y+1))/2))+y);
cout << “The sum for the 2 numbers is ” << sum << “\n”;

}

return 0;
}