+ 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; }
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;
+ 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
Post your try!!
0
didnt save Jayakrishna🇮🇳 :) i will try again xD
0
Save it and share link..