Aplicatie vectori
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Aplicatie vectori PowerPoint PPT Presentation


  • 60 Views
  • Uploaded on
  • Presentation posted in: General

Aplicatie vectori. Maximul dintr-un vector. Problema. Se citesc de la tastatura notele a n elevi la un extemporal. Se cere sa se gaseasca nota maxima atinsa la extemporal precum si numarul elevilor care au atins aceasta nota. Analiza datelor. Date de intrare:

Download Presentation

Aplicatie vectori

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Aplicatie vectori

Aplicatie vectori

Maximul dintr-un vector


Problema

Problema

  • Se citesc de la tastatura notele a n elevi la un extemporal. Se cere sa se gaseasca nota maxima atinsa la extemporal precum si numarul elevilor care au atins aceasta nota


Analiza datelor

Analiza datelor

  • Date de intrare:

    n, numar natural => numarul elevilor

    v, vector de dimensiune n => cele n note

  • Date de iesire:

    max, numar natural => nota maxima

    k, numar natural => numarul de elevi care au atins nota max


Un exemplu

Un exemplu

  • N=20

  • V=(6,8,9,5,9,5,7,10,7,5,8,10,8,10,7,9,10,9,8,4)


Un exemplu1

Un exemplu

  • N=20

  • V=(6,8,9,5,9,5,7,10,7,5,8,10,8,10,7,9,10,9,8,4)

  • Rezolvare:

  • Pasul 1.: cautare element maxim: max=10


Un exemplu2

Un exemplu

  • N=20

  • V=(6,8,9,5,9,5,7,10,7,5,8,10,8,10,7,9,10,9,8,4)

  • Rezolvare:

  • Pasul 1.: cautare element maxim: max=10

  • Pasul 2.: numarare aparitii element maxim: k=3


Un exemplu3

Un exemplu

  • N=20

  • V=(6,8,9,5,9,5,7,10,7,5,8,10,8,10,7,9,10,9,8,4)

  • Rezolvare:

  • Pasul 1.: cautare element maxim: max=10

  • Pasul 2.: numarare aparitii element maxim: k=3

  • Pasul 3.: afisare rezultat: Nota maxima este 10 si a fost atinsa de 3 elevi


Elaborare algoritm

Elaborare algoritm

  • Algoritmul in limbajul Pascal

    Program extemporal;

    Type vector=array[1..50] of byte;

    Var v:vector;

    n,I,max,k:byte;

    Begin

    write(‘Dati numarul de elevi: ‘); read(n);

    for i:=1 to n do

    begin write(‘nota elevului cu nr ‘,I,’ : ‘); read(v[i]); end;

    max:=v[1];

    for i:=2 to n do

    if v[i]>max then max:=v[i];

    k:=0;

    for i:=1 to n do

    if v[i]=max then k:=k+1;

    write(\Nota maxima este ‘,max,’ si a fost atinsa de ‘,k,’elevi’);

    end


Problema1

Problema

  • Se citesc n numere intregi. Sa se afiseze cel mai mare numar obtinutdin prima cifra a fiecarui numar


Analiza datelor1

Analiza datelor

  • Date de intrare:

    n, numar natural => numarul de numere

    de n ori cate un a => cele n numere

  • Date de iesire:

    nr => numarul maxim care se poate forma

  • Date de manevra>

    d, vectorul care contine prima cifra a fiecarui numar citit


Algoritmul problemei

Algoritmul problemei

  • var d:array[1..20] of byte;

  • a,i,c,aux,j,nr,n:longint;

  • begin

  • write('dati nr de nr');readln(n);

  • writeln('Dati elem: ');

  • for i:=1 to n do

  • begin

  • readln(a);

  • aux:=a;

  • while aux<>0 do begin

  • c:=aux mod 10;

  • aux:=aux div 10; end;

  • d[i]:=c end;

  • for i:=1 to n-1 do

  • for j:=i+1 to n do

  • if d[i]<d[j] then begin

  • aux:=d[i];

  • d[i]:=d[j];

  • d[j]:=aux end;

  • for i:=1 to n do nr:=nr*10+d[i];

  • writeln('Cel mai mare nr este: ',nr);

  • readln

  • end.


  • Login