fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a[8]={1,0,3,0,3,6,7,2};
  8. const size_t n = sizeof(a) / sizeof(a[0]);
  9. size_t pos;
  10. int Min;
  11.  
  12. /* find first non-zero position*/
  13. for(pos=0; a[pos]==0 && pos < n; ++pos);
  14.  
  15. if(pos==n) {
  16. /* if position == n , all zero*/
  17. cout << "all of element are zero\n";
  18. } else {
  19. /* find min */
  20. Min = a[pos];
  21. for(++pos; pos<n; ++pos)
  22. if(a[pos] < Min && a[pos]!=0)
  23. Min = a[pos];
  24. cout << Min << endl;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
1