Question

In: Computer Science

How to make an array without setting size?c++ cant figure this out without wanting to make...

How to make an array without setting size?c++

cant figure this out without wanting to make a vector or set a fixed size to the numbers.

Prompt the user to ask how many numbers you wish to read. Then based on that fill out the elements of one dimensional array with integer numbers. Then sort the numbers and print the original and sorted numbers in ascending order side by side.

Solutions

Expert Solution

Ans

code:-

#include <iostream>

using namespace std;

int main()

{

int n;

cout << "Enter size of Array"<<endl;

cin>>n;

int a[n];

cout<<"Enter "<<n<<" elements"<<endl;

for(int i=0;i<n;i++)

cin>>a[i];

cout<<"Elements of Array are:"<<endl;

for(int i=0;i<n;i++)

cout<<a[i]<<" ";

cout<<endl;

//sort

for(int i=0;i<n-1;i++){

for(int j=0;j<n-i-1;j++){

if(a[j+1]<a[j]){

int temp=a[j+1];

a[j+1]=a[j];

a[j]=temp;}

}

}

cout<<"Elements of Array after sorting are:"<<endl;

for(int i=0;i<n;i++)

cout<<a[i]<<" ";

return 0;

}

Input from user store in variable then declare array with size of that variable.

If any doubt ask in the comments.


Related Solutions

The anwsers that was given is not correct. I have tried but cant figure it out>...
The anwsers that was given is not correct. I have tried but cant figure it out> out You are evaluating a project for The Ultimate recreational tennis racket, guaranteed to correct that wimpy backhand. You estimate the sales price of The Ultimate to be $440 per unit and sales volume to be 1,000 units in year 1; 1,250 units in year 2; and 1,325 units in year 3. The project has a 3-year life. Variable costs amount to $245 per...
What I have bolded is what is wrong with this function and cant figure out what...
What I have bolded is what is wrong with this function and cant figure out what needs to bee done to get the second position of this comma?Need help building this function to do what the specifications say to do import introcs def second_in_list(s): """ Returns: the second item in comma-separated list    The final result should not have any whitespace around the edges.    Example: second_in_list('apple, banana, orange') returns 'banana' Example: second_in_list(' do , re , me , fa...
Is it possible to figure out, WITHOUT THE USE OF GRAPH, if the sample of a...
Is it possible to figure out, WITHOUT THE USE OF GRAPH, if the sample of a data comes from Normal Distribution? If it is possible that by doing some kind of mathematical calculation we can find if a distribution is normal or not? If you could share some example(s), that would be great.
c++ I need a code that will fill an array size of 1000, an array of...
c++ I need a code that will fill an array size of 1000, an array of size 2000, and an array size of 10000, with random int values. Basically like this: array1[1000] = filled all with random numbers array2[2000] = filled all with random numbers array3[10000] = filled all with random numbers C++ no need for print
Cant seem to figure out what is wrong here? On December 31, after adjustments, Gonzalez Company's...
Cant seem to figure out what is wrong here? On December 31, after adjustments, Gonzalez Company's ledger contains the following account balances: 101 Cash $ 94,400 Dr. 111 Accounts Receivable 35,600 Dr. 121 Supplies 8,000 Dr. 131 Prepaid Rent 81,200 Dr. 141 Equipment 128,000 Dr. 142 Accumulated Depreciation—Equip. 4,000 Cr. 202 Accounts Payable 17,000 Cr. 301 Emilio Gonzalez, Capital (12/1/2019) 131,240 Cr. 302 Emilio Gonzalez, Drawing 16,400 Dr. 401 Fees Income 327,200 Cr. 511 Advertising Expense 11,600 Dr. 514 Depreciation...
how to make a program in c++ that has an array that holds up to 25...
how to make a program in c++ that has an array that holds up to 25 digits.Then have a user input 25 values and check to see if each input value is between 10 and 50?
How to make a 2D array Tic Tac Toe game in C?
How to make a 2D array Tic Tac Toe game in C?
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array...
IN C++ (THIS IS A REPOST) Design a class, Array, that encapsulates a fixed-size dynamic array of signed integers. Write a program that creates an Array container of size 100 and fills it with random numbers in the range [1..999]. (Use std::rand() with std::srand(1).) When building the array, if the random number is evenly divisible by 3 or 5, store it as a negative number. Within your main.cpp source code file, write a function for each of the following processes....
In c++ Array expander Write a function that accepts an int array and the arrays size...
In c++ Array expander Write a function that accepts an int array and the arrays size as arguments. The function should create a new array that is twice the size of the argument array. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a...
How to figure out haplotypes?
How to figure out haplotypes?  Site 1               Site 2               Site 3               Site 4   Mother             GT                   AA                   GG                  AT Father             TT                    AG                   CT                   AA Child 1             GT                   AA                   GT                   AT Child 2             TT                    AA                   GT                   AA Child 3             TT                    AG                   CG                  AA  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT