The Array below reads 5 numbers and prints the largest number,but what changes i should make to print out the smallest number??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

The Array below reads 5 numbers and prints the largest number,but what changes i should make to print out the smallest number???

#include <iostream> using namespace std; const int n=5; int x[n]; int main(){ int largestNO=0; largestNO =x[0]; cout<<"enter 5 integers"<<endl; for(int i=0;i<n;i++){ cin>>x[i]; cout <<x[i]<<endl; } for(int i=0;i<n;i++){ if(x[i]>largestNO){ largestNO =x[i]; } } cout <<"the largest no is::"<<largestNO<<endl; return 0; }

14th Jul 2017, 12:52 PM
RiGeL
RiGeL - avatar
3 Answers
+ 10
just change > to < at if condition & no need to initialize largestno
14th Jul 2017, 3:10 PM
khadeeja Shamna
khadeeja Shamna - avatar
+ 3
Simply change > to < when comparing each element
14th Jul 2017, 12:56 PM
aklex
aklex - avatar
+ 2
@aklex thank u ,i tried that but i dont know why it gave me no output..i feel like it is sth more than changing the > sign....😐
14th Jul 2017, 2:06 PM
RiGeL
RiGeL - avatar