Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4
// read comments #include <iostream> using namespace std; int main() { int n; cin >> n; //size of the array //your code goes here int *nums=new int[n]; // array pointer of type integer having size n; for (int x=0;x<n;x++){ cin>>nums[x]; // taking input of n elements into nums array.. } int max = nums[0]; // first element value in max ; // Then is loop compares each value of array with max value. If element is greater than max then change max value to current element in loop.. for(int i=0; i<n; i++) { if(nums[i]>max) max = nums[i]; } // finally print max value.. cout << max; } Ex: 3 2 5 4 Here n = 3 Then Max = 2 In loop : 2 > 3 false 5 > 3 true so max = 5 4 > 5 false Max = 5 prints. Hope it helps...
30th Nov 2022, 8:07 PM
Jayakrishna 🇮🇳