import java.util.Scanner;
class Main {
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
System.out.println ("Let's play the lottery!");
System.out.println ("Enter an integer from 0 to 100");
boolean won = false;
int x = 0;
x = input.nextInt ();
if (x > 100)
{
System.out.println ("You entered a number outside the specified limits!");
System.out.println ("Enter a new number");
x = input.nextInt ();
}
if (x < 0)
{
System.out.println ("You entered a number outside the specified limits!");
System.out.println ("Enter a new number");
x = input.nextInt ();
}
if (x == 10)
{
System.out.println ("You are lucky. You won 100$");
won = true;
}
if (x == 50)
{
System.out.println ("Luck is always with you. You won 10$");
won = true;
}
if (x == 99)
{
System.out.println ("Good job. You won 50$");
won = true;
}
if (x == 1)
{
System.out.println ("The winning is 20$");
won = true;
}
if (!won)
{
System.out.println("You are not lucky. Try next time");
}
System.out.println ("End!");
}
}
Объяснение:
на Free Pascal
Объяснение:
var
a : integer;
n, i, big, nc, ncount : integer;
begin
writeln('Введите количество чисел :');
readln(n);
big := 0;
nc := 0;
ncount := 0;
for i := 1 to n do begin
writeln('Введите ', i, ' число:');
readln(a);
if a>20 then
big := big + a;
if (a mod 2) <> 0 then begin
nc := nc + a;
inc(ncount);
end;
end;
writeln('Сумма чисел > 20 = ', big);
writeln('Среднее арифметическое ',ncount,' нечётных чисел =', nc/ncount:2:2);
end.