Assignment 8 NEW
Assignment 8 NEW
system ("pause");
return 0;}
2. Write a program that has a function that output the numbers and their squares between 1 and 10 using
the following prototypes:
a. void squares (int x);
#include <iostream>
using namespace std;
void
squares (int x)
{
for (int i = x; i <= 10; i++)
cout << "The Square of" << i << "is" << (i * i) << endl;
}
int
main ()
{
int x = 1;
squares (x);
system ("pause");
return 0;
#include <iostream>
using namespace std;
void
squares (void)
{
int x = 1;
int
main ()
{
squares ();
system ("pause");
return 0;
3. Write a program that ask the user to input two double numbers: n1 and n2 (n1 must be less than n2).
Your program should include three functions to perform the following:
a. Output all odd numbers between n1 and n2.
b. Output the sum of all even numbers between n1 and n2.
c. Output the sum of the square of the odd numbers between n1 and n2.
#include <iostream>
#include <cmath>
using namespace std;
void
odd (double n1, double n2)
{
void
SumE (double n1, double n2)
{
int d = 0;
for (int i = ceil (n1); i <= floor (n2); i++)
{
if (i % 2 == 0)
d = d + i;
}
cout << "Sum of Even Interger is " << d;
}
void
sumSqrOdd (double n1, double n2)
{
int o = 0;
int s = 0;
int
main ()
{
cout << "Enter 2 integers: " << endl;
double n1, n2;
cin >> n1 >> n2;
odd (n1, n2);
cout << endl;
SumE (n1, n2);
cout << endl;
sumSqrOdd (n1, n2);
cout << endl;
system ("pause");
return 0;
}
4. Write a program that has a function to find the sum of all the integers between 0 and x. x is an
integer entered by the user. Use the following prototypes: void sum (int x);
#include <iostream>
using namespace std;
void sum(int x)
{
int sum = 0;
for (int i = 0; i <= x; i++)
{
sum = sum + i;
}
] cout << sum;
}
int main()]
{
int x;
cin >> x;
sum(x);
cout << endl;
system("pause");
return 0;
}