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

Cant figure out why my out is wrong for my c++ program. for example if the...
Cant figure out why my out is wrong for my c++ program. for example if the initial value is 100, the intrest rate is 10%, and it takes 6 months for maturity the output should be $105 but instead it outputs 101.657 please help. #include <iostream> #include <cmath> using namespace std; struct account { double balance; double interest_rate; int term; }; void info(account& accountinfo); int main(void) { double calc1, calc2, calc3; account accountinfo; info(accountinfo); calc1 = accountinfo.interest_rate / 100; calc2...
Implement a stack in C++ using an array, not an array list. Make your stack size...
Implement a stack in C++ using an array, not an array list. Make your stack size 5 when you test it, but do not hardcode this! You should be able to change the size for testing purposes with the change of one variable. DO NOT use Stack class defined in C++ Implement the following methods in your stack class. stack() creates an empty stacks, stack s is new and empty. push(item) adds a new item to the stack s, stacks...
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...
In C++ Write a function that took in SIZE and array [size] and counted the number...
In C++ Write a function that took in SIZE and array [size] and counted the number of elements >100
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?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT