Problema 1. Scrieti un program care calculeaza suma si produsul numerelor prime dintr-un tablou unidimensional A[1..N], N<=100, cu numere naturale.
Uses CRT;
Type T=Array[1..100] Of Integer;
Var A:T; N,I,K,S:Integer; P:Longint; V:Boolean;
Begin ClrScr; Write('introdu nr de elemente=:'); Read(N);
For I:=1 To N Do Begin
Write('A[',I,']='); Read(A[I])
End;
S:=0; P:=1;
For I:=1 To N Do Begin
K:=2; V:=True;
While V And (K<=A[I] Div 2) Do
If A[I] Mod K=0 Then V:=False Else Inc(K);
If V Then Begin S:=S=A[I]; P:=P*A[I] End
End;
Write('Suma=',S,' Produsul=',P);
ReadKey End.
Problema 2. Scrieti un program care calculeaza miinim si numarul de elemente minime dintr-un tablou unidimensional A[1..N], N<=100, cu numere intregi.
Uses CRT;
Type T=Array[1..100] Of Integer;
Var A:T; N,I,Min,K:Integer;
Begin ClrScr; Write('introdu nr de elemente=:'); Read(N);
For I:=1 To N Do Begin
Write('A[',I,']='); Read(A[I])
End;
Min:=A[1]; K;=1;
For I:=2 To N Do
If A[I]<Min Then Begin Min:=A[I]; K:=1 End
Else If A[I]=Min Then Inc(K);
Write('Minim=',Min,' Numarul=',K);
ReadKey End.
Problema 3. Scrieti un program care ordoneaza tabloul unidimensional A[1..N], N<=100, cu numere intregi in ordine descresctoare.
Uses CRT;
Type T=Array[1..100] Of Integer;
Var A:T; N,I,C:Integer; V:Boolean;
Begin ClrScr; Write('introdu nr de elemente=:'); Read(N);
For I:=1 To N Do Begin
Write('A[',I,']='); Read(A[I])
End;
V:=True;
While V Do Begin V:=False;
For I:=1 To N-1 Do
If A[I]<A[I+1] Then Begin V:=True; C:=A[I]; A[I]:=A[I+1]; A[I+1]:=C End
End;
WriteLn('Tabloul ordonat');
For I;=1 To N Do Write(A[I],' ');
ReadKey End.
Atentie!!! Pentru saptamina viitoare ne pregatim de evaluare la tema: Tablouri unidimensionale.
Niciun comentariu:
Trimiteți un comentariu