Question

In: Computer Science

write in C++ as simple as possible please and thanks don't use header file <bits/stdc++.h> All...

write in C++ as simple as possible please and thanks

don't use header file <bits/stdc++.h>

  1. All programs work with binary numbers which are powers of 2 (2, 4, 8, …).  Write a program that will have a user enter a number (n) less than 10,000. Then have the program put each power of 2 (int) into an array up to and possibly including the number n. This means you don't know at the start how large the array will be, so estimate.  Fill the original arrays with all zeros, and then loop through the array and fill the array with powers of 2 up to the number n.  For example, if the user entered 8 then the array would contain 2, 4, 8. Then have the program print out all the numbers in the array. For example:

2

4

8

      Don't forget to put comments at the top of your code

Solutions

Expert Solution

Code:

//program which prints numbers powers of 2 in a given number
#include <iostream>
#include<cmath>
using namespace std;
int main() {
int n;
//prompts the user for input
cout<<"Enter a number less than 10,000: ";
cin>>n;
int arr[20] = { };
cout<<"The array elements are: "<<endl;
//loop to store elements in array
for(int i=1;pow(2,i)<=n;i++)
{
arr[i] = pow(2,i);
cout<<arr[i]<<endl;
}
return 0;
}

Screenshot:-

Output:-


Related Solutions

PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find...
PS: Please don't use #include <bits/stdc++.h>. Visual studio compatible please. Write a C++ program to find least common multiple (LCM) of two, three and four integer values. The integer values are entered from the keyboard and the outputs are printed to the console. The LCM of two, three and four integer values are computed using Prime factorization method. You have to use arrays to hold input values and use functions/methods to get data from the keyboard, display output to the...
Please write code in C++ and include all header files used not bits/stdc: (Same number subsequence)...
Please write code in C++ and include all header files used not bits/stdc: (Same number subsequence) Write an O(n) program that prompts the user to enter a sequence of integers ending with 0 and finds longest subsequence with the same number. Sample Run Enter a series of numbers ending with 0: 2 4 4 8 8 8 8 2 4 4 0 The longest same number sequence starts at index 3 with 4 values of 8
(C++. Please don't use #include <bits/stdc++.h>) This lab exercises your understanding of using a Heap to...
(C++. Please don't use #include <bits/stdc++.h>) This lab exercises your understanding of using a Heap to create a Priority Queue Follow these steps: Declare an integer array to use for the heap (size of 20 to 30 elements) Create an insertion function (and any needed helper functions) that creates a min-heap (smallest priority is most important) Create a remove function (and any needed helper functions) that removes the min value from the heap and returns it In main, call the...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define...
Use the functions.h header file with your program (please write in C code): #ifndef FUNCTIONS_H #define FUNCTIONS_H typedef struct MyStruct { int value; char name[ 100 ]; } MyStruct; void sortArray( MyStruct*, int ); void printArray( MyStruct*, int ); #endif Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like...
I want flowchart process for this code c++ _____________________ #include<bits/stdc++.h> using namespace std; int main() {...
I want flowchart process for this code c++ _____________________ #include<bits/stdc++.h> using namespace std; int main() { char repeat = 'Y'; for (;repeat == 'Y';){ char empname[222]; float basicSalary, h_r_a, DearnessAllow, tax, netSalary; int e_id; cout<<"\nEmployee Name :"; cin>>empname; cout<<"\nEmployee Id :"; cin>>e_id; cout << "Enter Basic Salary : "; cin >> basicSalary; DearnessAllow = 0.30 * basicSalary; h_r_a= 800; switch (1) { case 1: if (basicSalary <= 2,50,000) tax = 0; case 2: if (basicSalary > 250000 && basicSalary <=...
If possible, please answer all 4 questions. Thanks! :) 35. What file in the /proc directory...
If possible, please answer all 4 questions. Thanks! :) 35. What file in the /proc directory can be used to list the features supported by your system’s CPU? 36. Which of the following commands can be used to insert a kernel module into the Linux kernel? (Choose all that apply.) a. insmod b. modprobe c. lsmod d. depmod
Can someone please write me a header file in c++ using the quadratic probing hash method...
Can someone please write me a header file in c++ using the quadratic probing hash method that will work with this program? #include "hash.h" #include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <list> using namespace std; const size_t KEYS_COUNT = 1000; // Number of keys to generate for testing string random_key(); class HashCheck { private: size_t count; Hash hash; public: HashCheck(Hash& h) { count = 0; hash = h; } void operator() (const string key) { if (hash[key] !=...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
Write a C++ program that design a class definition to be put in a header file...
Write a C++ program that design a class definition to be put in a header file called fizzjazz.h A store sells online FizzJazz which are sound tones made by famous bands. For each FizzJazz, the store wants to keep track of the following attributes: * title - the name of the sound tone * band - Famous band name that created the tone * duration - this is in seconds and may be fractional: examples: 20.0, 34.5 Each attribute will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT