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 ......
CODE MUST BE IN C++ write a program that loops a number from 1 to 10...
CODE MUST BE IN C++ write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above...
Write a program in C to perform the following: Generates an array of 10 double random...
Write a program in C to perform the following: Generates an array of 10 double random values between 1.0 and 100.0 – assume these are prices for 10 items that a store sells Generates an array of 10 integer random values between 0 and 200 – assume that these are the number of items/units (first array) sold Generate another array called “itemSale” which would contain the total sale for each item. Calculate the total sale for this store and display...
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...
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT