Question

In: Computer Science

Please use C++ 1. A Sequence of numbers and a sum is given as input. List...

Please use C++

1. A Sequence of numbers and a sum is given as input. List all combinations of numbers that can add upto the given Sum.

User input:-

Enter numbers: -   1, 3,7,9,11

Enter a sum :- 20

Output:

11+9 = 20

1+3+7+9 = 20

2. Print absolute prime numbers between a given range:-

Enter Range - 2,99

For eg Prime numbers are:-

Prime numbers ==> 2,3,5,7,11,13,17,19,23

Absolute Prime numbers ==> 2,3,5,7,11,23

3. Write an encoder and decoder program, which should give us options to encode/decode?

  

   Do you want to encode or decode? [e,d]

   >>e

   Enter string to encode :- "Hello How are you?"

   Encoded string: "SDFAF@sfdfrtre"

   Do you want to encode or decode? [e,d]

   >>d

   Enter string to decode:- "SDFAF@sfdfrtre"

   Decoded string: "Hello How are you?"

Solutions

Expert Solution

1. #include<bits/stdc++.h>

using namespace std;

void unique (int l, int s, int k, vector<int>& local, vector<int>& a)

{

if (s==k)

{

cout<<"{";

for(int i=0; i< local.size();i++){

if(i!=0)

cout<<", ";

cout<<local[i];

if(i!= local.size()-1)

cout<<" , ";

}

cout<<" }"<<endl;

return;

}

for(int i=1; i < a.size(); i++){

if(s +a[i] > k)

continue;

if(i and a[i] == a[i -1] and i >l)

continue;

local.push_back(a[i]);

unique(i+1, sum + a[i], k, local, a);

local.pop_back();

}

}

void com(vector<int> a, int k)

{

sort(a.begin(), a.end());

vector<int> local;

unique(0,0,k,local,a);

}

int main()

{

vector<int> a={10,1,2,7,6,1,5};

int k= 8;

com(a,k);

return(0);

}

2) #include<upstream.h>

using namespace std;

void prime(int n)

{

int d=0;

for(int i=2; i<= n/2; i++)

{

if(n%i == 0)

d++;

}

if(d==1)

cout<<n<<endl;

}

int main()

{

cout<<" Enter range";

int l,u;

cin>>l>>u;

cout<<" Prime nos between " <<l<<" and "<<" are:"<<endl;

for(int i=l;i<= u; i++)

prime(i);

return 0;

}

3)


Related Solutions

CODE IN C PLEASE Ask for user to input 4 different numbers Use pointers in calculations...
CODE IN C PLEASE Ask for user to input 4 different numbers Use pointers in calculations instead of variables to calculate the sum of those 4 numbers Print the sum Use a pointer to a pointer for print operation
python: ask the user to input a sequence of positive numbers. the end of the sequence...
python: ask the user to input a sequence of positive numbers. the end of the sequence is determined when the user enters a negative number. print out the maximum number from the sequence. output: keep entering positive numbers. to quit, input a negative number. enter a number: 67 enter a number: 5 enter a number: 8 enter a number: -3 largest number entered: 67 (note: i do not want to ask the user how many numbers they will input)
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem...
Using C++ use dynamic programming to list first 30 Fibonacci numbers. Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently using dynamic programming. Create a program that uses dynamic programming techniques to list the first 30 Fibonacci numbers.
Input 10 integers and display the following: a. the sum of even numbers. b. the sum...
Input 10 integers and display the following: a. the sum of even numbers. b. the sum of odd numbers. c. the largest integer d. the smallest integer e. the total count of even numbers f. the total count of odd numbers. Using C++ program with for loop..
in C please! Write a code that asks user for input N and calculates the sum...
in C please! Write a code that asks user for input N and calculates the sum of the first N odd integers. There should be a "pure" method that calculates the sum separately that Main method should call when printing the output.
C++ Create the code Read  numbers from stdin and print their sum to stdout. Input Format One...
C++ Create the code Read  numbers from stdin and print their sum to stdout. Input Format One line that contains  space-separated integers:a , b, c and . Constraints 1≤ a,b,c ≤1000 Output Format Print the sum of the three numbers on a single line. Sample Input 1 2 7 Sample Output 10 Explanation The sum of the three numbers is 1+2+7=10
Both TCP and RTP use sequence numbers. Investigate whether or not the sequence numbers in the...
Both TCP and RTP use sequence numbers. Investigate whether or not the sequence numbers in the TCP and RTP protocols play the same role.
5. Find the sum of terms in given arithmetic sequence 1 + 3 + 5 +...
5. Find the sum of terms in given arithmetic sequence 1 + 3 + 5 + ... + 59 6. Find the sum of terms in given arithmetic sequence 2 + 5 + 8 + ... + 41 7.Given a geometric sequence 6 + 2 + 2/3 + ... is this sequence converging or diverging, if it is converging find it's sum
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 2 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT