Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that calculates and prints the sum of the even integers from 2 t

ID: 3670636 • Letter: W

Question

Write a program that calculates and prints the sum of the even integers from 2 to 30. Write a program that calculates and prints the product of the odd integers from I to 15. The factorial function is used frequently in probability problems. The factorial of a positive integer n (written a-and pronounced "a factorial's is equal to the product of the positive integers from I to n. Write a program that evaluates the factorials of the integers from 1 to Print the results in tabic format. Practice #4 (Nested for loops) One interesting application of computers is drawing graphs and bar charts (sometimes called histograms'). Write a program that gets a number from the user and then a line containing that number of adjacent). For example, it your program gets the number 7. it should print *******. Your program should allow the user to do this 5 times.

Explanation / Answer

All the solution programs are written in C++, as per the requirements

1.

#include <iostream>
using namespace std;
int main()
{
int sum =0;
for (int i = 2; i <= 30; i++){
if ( i%2 == 0) {
sum = sum + i;
}
}
cout<<"Sum of the even integers from 2 to 30 is "<<sum<<endl;
return 0;
}

2.

#include <iostream>
using namespace std;
int main()
{
int prod =1;
for (int i = 1; i <= 15; i++){
if ( i%2 != 0) {
prod = prod * i;
}
}
cout<<"Product of the odd integers from 1 to 15 is "<<prod<<endl;
return 0;
}

3.

#include <iostream>
using namespace std;
int factorial(int);
int main()
{
int fact;
cout<<"Number Factorial"<<endl;
cout<<"------ ---------"<<endl;
   for (int i = 1; i <= 5; i++){
   fact=factorial(i);
   cout<<i<<" "<<fact<<endl;
   }

return 0;   

}

int factorial(int number) {
   int temp;
   if(number <= 1) return 1;
   temp = number * factorial(number - 1);
   return temp;
}

4.

#include <iostream>
using namespace std;
int factorial(int);
int main()
{
int input;
for (int i = 1; i <= 5; i++){
cout<<"Please input a number: ";
cin>>input;
  
   for (int j = 1; j <= input; j++){
   cout<<"*";
   }
   cout<<endl;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote