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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.