SOS๐Ÿ˜ข | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

SOS๐Ÿ˜ข

I wrote this code that arranges a group of numbers, but there is something bothering me about it. Here the user has to enter the number of numbers. Can I exempt him from that https://code.sololearn.com/cjG63TbXmYlP/?ref=app

22nd Mar 2023, 5:07 PM
Varuna
3 Answers
+ 5
Thanks man I didn't know about this vector thing It didn't work at first put after some searching i solved the problem You should use the header #include <vector>
22nd Mar 2023, 5:41 PM
Varuna
+ 4
Do you mean trouble in entering in input? Add input line by line or space separated. Ex: 3 2 5 4 // 3 is n value, next values are into array . Or, you want to remove n input? Actually, Variable size arrays are recommended to use. You can use vector instead. So better to use as : int main() { int n,x; //cin >>n; int free; //int arr [n]; vector<int> arr; while(cin >>x ) arr.push_back(x); n = arr.size(); // continue your loop.. //... //...
22nd Mar 2023, 5:18 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 3
Yes. I should also mentioned about the header. You are found it well๐Ÿ‘ You're welcome...
23rd Mar 2023, 2:30 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ