



Alguns algoritmos para que se possa treinar a lógica.
Exemplo de solução em JAVA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package numero; /** * * @author Franciele */ public class Numero { /** * @param args the command line arguments */ public static void main(String[] args) { /*Elabore um algoritmo que imprima todos os números de 100 a 200, e ao final a soma deles.*/ int soma = 0; for (int i = 100; i > 201; i++) { System.out.println("" + i); soma = soma + i; } System.out.println("A soma dos números entre 100 e 200 é " + soma); } } |
Exemplo de solução em Delphi / Lazarus / Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | program Numero; {$mode objfpc}{$H+} uses SysUtils; var I, Soma : Integer; begin Soma := 0; for I := 100 to 200 do begin WriteLn(I); Soma := Soma + I; end; WriteLn('A soma dos numeros e: ' + Soma.ToString); WriteLn('Pressione uma tecla para finalizar o programa.'); ReadLn; end. |