Houssey
Moderator
 Din: Buzau
Inregistrat: acum 17 ani
Postari: 260
|
|
{Se da un vector cu n componente , numere naturale. Sa se afiseze cel mai mare numar rational subunitar, in care numaratorul si numitorul fac parte din vectorul dat. Ex. Pentru n=3, x=(1,3,2) ( cel mai mare numar rational subunitar va fi 2/3} var x:array[1..100] of integer; i,n,p,k:integer; t:real; s:boolean; begin repeat write('n=');readln(n); until (n>0) and (n<100); writeln('ATENTZIE!!!!! DATZI ELEMENTELE DISTINCTE INTRE ELE SHI DIFERITE DE ZERO'); for i:=1 to n do begin write('x[',i,']=');readln(x[i]); end; repeat s:=true; for i:=1 to n-1 do if x[i]>x[i+1] then begin k:=x[i]; x[i]:=x[i+1]; x[i+1]:=k; s:=false; end; until s; writeln; writeln('vectorul ordonat crescator:'); for i:=1 to n do begin writeln('x[',i,']=',x[i]); end; t:=x[1]/x[2]; p:=1; for i:=2 to n-1 do if (t<x[i]/x[i+1]) then begin t:=x[i]/x[i+1]; p:=i; end; writeln; writeln('cel mai mare numar rational subunitar este ',x[p],'/',x[p+1]); readln;readln; end.
_______________________________________ House Music Set`s Me Free!
|
|