Question

In: Computer Science

Using c++, Write a program to perform the multiplication of 10 consecutive number starting from 5?...

Using c++, Write a program to perform the multiplication of 10 consecutive number starting from 5?

Write a program to perform the summation of 10 even number starting from 2?

Write a program to perform the summation of 10 odd number starting from 2?

Write a program to perform the summation of 10 number starting from 2 and increment is

given by user?

Write a program to combine all operations from 1 to 4 in a single program using ‘Switch’

statement. Ask user whether they want to continue or not after one run of the program.

Solutions

Expert Solution

A program to perform the multiplication of 10 consecutive numbers starting from 5?

#include <iostream>

using namespace std;

int main()
{
long n = 1;
for(int i=5; i<15; i++)
{
n = n*i;
}
cout<<n;

return 0;
}


OUTPUT:

A program to perform the summation of 10 even numbers starting from 2?

#include <iostream>

using namespace std;

int main()
{
int sum = 0;
for(int i=2; i<=20; i++)
{
if(i%2==0)
sum = sum + i;
}
cout<<sum;

return 0;
}

OUTPUT:

A program to perform the summation of 10 odd numbers starting from 2?

#include <iostream>

using namespace std;

int main()
{
int sum = 0;
for(int i=2; i<=21; i++)
{
if(i%2!=0)
sum = sum + i;
}
cout<<sum;

return 0;
}

OUTPUT:

A program to perform the summation of 10 numbers starting from 2 and increment is given by the user?

#include <iostream>

using namespace std;

int main()
{
int sum = 2, inc, nextTerm;
cout<<"Enter the increment value: ";
cin>>inc;
  
nextTerm = sum+inc;
  
for(int i=1; i<10; i++)
{
sum = sum + nextTerm;
nextTerm = nextTerm + inc;
}
cout<<sum;

return 0;
}

OUTPUT:

Write a program to combine all operations from 1 to 4 in a single program using the ‘Switch’ statement. Ask the user whether they want to continue or not after one run of the program.

#include <iostream>

using namespace std;

void mul10Con()
{
long n = 1;
for(int i=5; i<15; i++)
{
n = n*i;
}
cout<<n;
}

void sum10Even()
{
int sum = 0;
for(int i=2; i<=20; i++)
{
if(i%2==0)
sum = sum + i;
}
cout<<sum;
}

void sum10Odd()
{
int sum = 0;
for(int i=2; i<=21; i++)
{
if(i%2!=0)
sum = sum + i;
}
cout<<sum;

}

void sum10User()
{
int sum = 2, inc, nextTerm;
cout<<"Enter the increment value: ";
cin>>inc;
  
nextTerm = sum+inc;
  
for(int i=1; i<10; i++)
{
sum = sum + nextTerm;
nextTerm = nextTerm + inc;
}
cout<<sum;
}

int main()
{
int n;
char c;
while(true)
{
cout<<endl<<"1: Write a program to perform the multiplication of 10 consecutive number starting from 5";
cout<<endl<<"2: Write a program to perform the summation of 10 even number starting from 2";
cout<<endl<<"3: Write a program to perform the summation of 10 odd number starting from 2";
cout<<endl<<"4: A program to perform the summation of 10 numbers starting from 2 and increment is given by the user";
cout<<endl<<endl<<"Enter your choice: ";
cin>>n;
switch(n)
{
case 1:
mul10Con();
break;
case 2:
sum10Even();
break;
case 3:
sum10Odd();
break;
case 4:
sum10User();
break;
}
cout<<"\nDo you want to continue (y/n): ";
cin>>c;
if(c=='y' || c=='Y')
continue;
else
break;
}
return 0;
}

OUTPUT:


Related Solutions

Write a C++ program which prints consecutive dates to the console window starting at January 1,...
Write a C++ program which prints consecutive dates to the console window starting at January 1, 2000, as follows. Saturday, January 1, 2000 Sunday, January 2, 2000 Monday, January 3, 2000 Tuesday, January 4, 2000 ... You will define a function which prints the dates indefinitely, exactly as given above, or prints a specific number of dates. For example, if your function prints 7,581 days the result would look like this. Saturday, January 1, 2000 Sunday, January 2, 2000 ......
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
Write a C++ program that will read in the number of nodes (less than 10) and...
Write a C++ program that will read in the number of nodes (less than 10) and a adjacency relation representing a graph. The program will create an adjacency matrix from the adjacency relation. The program will then print the following items: 1. Print the adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists Sample run output Please input the number of nodes: 6 Please input the adjacency relation: {(1,2),(1,5),(2,1),(2,3),(3,2),(3,4),(4,3),(4,5),(5,1),(5,4)}...
Write a C++ program that will read in the number of nodes (less than 10) and...
Write a C++ program that will read in the number of nodes (less than 10) and a adjacency relation representing a graph. The program will create an adjacency matrix from the adjacency relation. The program will then print the following items: 1. Print the adjacency matrix 2. Determine if there are any isolated nodes and print them 3. Determine if an Euler path exists Sample run (to make program output more clear, I have put it in boldface): Please input...
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers...
1.Using C++ code, write a program named q4.cpp to compute the product (multiplication) of 4 integers a, b, c and d, where a is input by a user via the keyboard, b = 2a - 1, c = ab - 2 and d = |a - b - c|. 2.Using C++ code, write a program named q5.cpp to solve the equation 2n = 14.27 for n. 3.Using C++ code, write a program named q3.cpp to divide each of the elements...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) b. Use the binary search algorithm to search the list, switching to a sequentialsearch when the size...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 2 Use any sorting algorithm to sort list.
In C++ Write a program to find the number of comparisons using binarySearch and the sequential...
In C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list.
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses...
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
Need to write a code using c# Strassen’s Algorithm for matrix multiplication.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT