+ 1

how to change this into an array

#include <iostream> using namespace std; int main() { int n; cin>>n; int nums=0; cin>>nums; int min = nums; for(int i=1; i<n; i++) {cin>>nums; if(nums<min) min = nums; } cout << min; return 0; }

16th May 2022, 6:12 PM
learner
learner - avatar
9 Answers
+ 1
Instead of int variable nums, declare an array like int nums[n] then use like nums[i] in loop. Comment //cin>>nums; before trying, revise lesson arrays;
16th May 2022, 6:23 PM
Jayakrishna 🇮🇳
17th May 2022, 9:13 AM
learner
learner - avatar
+ 1
Jayakrishna🇮🇳 i got it right but i am unsatisfied xD i want to make the array instead of [5] it can accompany any size []
17th May 2022, 9:14 AM
learner
learner - avatar
+ 1
You can do like this: int n ; cin >> n; int ages[n]; But it is not recommended. Array are fixed length. You should mention length at compile time and you can't change it's size during run time. If you need, then use a vector type. It's a dynamic in nature. You can say it is like a dynamic array.
17th May 2022, 9:30 AM
Jayakrishna 🇮🇳
+ 1
17th May 2022, 9:31 AM
learner
learner - avatar
0
Jayakrishna🇮🇳 i still couldnt fix it into an array. 😭
17th May 2022, 7:52 AM
learner
learner - avatar
0
Post your try!!
17th May 2022, 8:18 AM
Jayakrishna 🇮🇳
0
didnt save Jayakrishna🇮🇳 :) i will try again xD
17th May 2022, 8:18 AM
learner
learner - avatar
0
Save it and share link..
17th May 2022, 8:21 AM
Jayakrishna 🇮🇳