Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Is this program correct for C++?explain the difference between print, voidprint,cout and cin /*Create a Program that complies with the following: a) Ask for two
Is this program correct for C++?explain the difference between print, voidprint,cout and cin /*Create a Program that complies with the following: a) Ask for two numbers b) Determine the range between these two numbers c) Show the prime numbers within the range d) Show the sum of the even and odd numbers within the range * / #include #include using namespace std; int odd(int min, int max) {int c, s = 0; for (c = min; c <= max; c++) { if (c % 2 == 1) { s += c;}} return s;} int even(int min, int max) {int c, s = 0; for (c = min; c <= max; c++) { if (c % 2 == 0) { s += c;} }return s;} int primo(int n) {for (int c = 2; c < n; c++) { if (n % 2 == 0) {return 0; }} return 1;} void printprimo(int min, int max) { cout << " Los numeros primos son : "; for (int c = min; c <= max; c++) { if (primo(c) == 1) { cout << c ; }} cout <<" ";} void print(int min, int max){ cout << " El rango de los numeros es: "; for (int c = min; c <= max; c++) { cout << c;} cout <<" ";} int main(){ int min, max; cout << " Ingrese el numero minimo: "; cin >> min; cout << " Ingrese el numero mayor: "; cin >> max; print(min, max); cout << " La suma de los numeros pares es: " << even(min, max) << endl; cout << " La suma de los numeros impares es: " << odd(min, max) << endl; printprimo(min, max); system("pause"); return 0;}
Is this program correct for C++?explain the difference between print, voidprint,cout and cin
/*Create a Program that complies with the following:
a) Ask for two numbers
b) Determine the range between these two numbers
c) Show the prime numbers within the range
d) Show the sum of the even and odd numbers within the range * /
#include
#include
using namespace std;
int odd(int min, int max)
{int c, s = 0;
for (c = min; c <= max; c++) {
if (c % 2 == 1) {
s += c;}}
return s;}
int even(int min, int max)
{int c, s = 0;
for (c = min; c <= max; c++) {
if (c % 2 == 0) {
s += c;}
}return s;}
int primo(int n)
{for (int c = 2; c < n; c++) {
if (n % 2 == 0) {return 0;
}}
return 1;}
void printprimo(int min, int max)
{
cout << " Los numeros primos son : ";
for (int c = min; c <= max; c++) {
if (primo(c) == 1) {
cout << c ;
}}
cout <<" ";}
void print(int min, int max){
cout << " El rango de los numeros es: ";
for (int c = min; c <= max; c++) {
cout << c;}
cout <<" ";}
int main(){
int min, max;
cout << " Ingrese el numero minimo: ";
cin >> min;
cout << " Ingrese el numero mayor: ";
cin >> max;
print(min, max);
cout << " La suma de los numeros pares es: " << even(min, max) << endl;
cout << " La suma de los numeros impares es: " << odd(min, max) << endl;
printprimo(min, max);
system("pause");
return 0;}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started