Treba uraditi program koji u mjenja clan niza sa prvim najvecim clanom ,a ako nema veceg mjenja ga sa nulom ,npr. 59361 90600 .
U qbasicu sam taj program uradio ovako i on radi
input "N=",n dim a(n) for x=1 to n input a(x) next x for x=1 to n s=0 p=0 r=a(x) v=0 while s<>1 and p<n p=p+1 if a(x)<a(x+p) then a(x)=a(x+p) s=1 end if wend if a(x)=r then a(x)=v next x for x=1 to n print a(x) next x input o end
Medjutim kad ga "prevedem" u c++
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
int n ;
int s=0 ;
int p,l ;
cout<<"n=" ;
cin>>n ;
int a[n] ;
cout<<"Unesi brojeve"<<endl;
for(int x=1;x<=n;x++){
cin>>a[x];
}
for(int i=1;i<=n;i++){
p=i ;
l=a[i];
while(s!=1 && p<n){
p++ ;
if(a[i]<a[p]){
a[i]=a[p];
s=1 ;
}
}
if(a[i]==l){
a[i]=0 ;
}
}
cout<<endl;
for(int u=1;u<=n;u++){
cout<<a[u]<<endl;
}
return 0;
}
Koje god brojeve da upisem za rezultat dobijem niz nula .