Informática, perguntado por jpds605, 1 ano atrás

Faça um programa que imprima os 10 primeiro números primos.
Tenho que fazer esse programa em visualg.

Soluções para a tarefa

Respondido por ribass
0
Tenho em pascal:

procedure TForm1.BitBtn1Click(Sender: TObject);
var i,xC: Integer;    xPrimo: String;

    function IsPrimo(wNumber : Integer) : Boolean;   
    var      x, wCount: Integer;   
    begin   
         wCount := 1;     
         for x := 2 to (wNumber div 2) do
            if (wNumber mod x = 0) then 
                Inc(wCount);     
         Result := (wCount = 1);   
    end;
begin 
     xC:=0;   
     xPrimo:='';
      for i:=2 to 100 do     
          Begin         
             if IsPrimo(i) then           
                Begin           
                   xPrimo:=xPrimo+IntToStr(i)+',';
                   inc(xC);           
                   if xC=10 then           
                     Begin                 
                        ShowMessage(xprimo);                 
                         Abort;
                     end;         
                 end;     
            end;
end;
Perguntas interessantes