how to change this into an array | Sololearn: Learn to code for FREE!

+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; }

c++

5/16/2022 6:12:09 PM

learner

9 Answers

New Answer

+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;

+1

https://code.sololearn.com/c8zh18xM5LQ6/?ref=app

+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 []

+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.

+1

thanks alot Jayakrishna🇮🇳

0

Jayakrishna🇮🇳 i still couldnt fix it into an array. 😭

0

0

didnt save Jayakrishna🇮🇳 :) i will try again xD

0

Save it and share link..