+ 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; }
3 Respuestas
+ 10
just change > to < at if condition & no need to initialize largestno
+ 3
Simply change > to < when comparing each element
+ 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....😐