Sei sulla pagina 1di 3

Department of Computer Science

SECOND LIST OF EXERCICES

15.­     Write   a   program  that  reads   a   sequence   of


numbers (ending with zero) and display at the end:
1.­ The greatest of the number entered.
2.­ The sentence “There are negative numbers”
if there are negative numbers. 
3.­ The average of the positive numbers 

16.­   Write   a   java   program   that   permits   to


introduce the names and the ages of  50 students.
At the end  display the average age, the name and
the age of the oldest student.

17.­ Write a program that permits to introduce the
age and the gender of 60 teachers. You must valid
that   the   gender   is   “M”   or   “F”.   The   age   must   be
between 18 and 70 years. You have to display how
many men and women there are over 45 years old.

18.­   Do   the   program   that   allows   to   type   two


numbers   and   display   its   product   calculated   by
successive sums.

19.­   Do   the   program   that   allows   to   type   two


numbers   and   display   the   result   of   raising   the
former   to   the   latter   calculated   by   successive
multiplication.

20.­   Do   the   program   that   allows   to   type   a


numerical   score   (between   0   and   10)   and   translate
it to alphabetic grade according to the following
chart:

0 <= GRADE < 3 MD
3 <= GRADE < 5 INS
5 <= GRADE < 6 SUF
6 <= GRADE< 7 BIEN
7 <= GRADE < 9 NOT
9 <= GRADE <= 10 SOB

Programing
Course 2011/2012 Pág. 1
Department of Computer Science

21.­ Do the program that allows to type a number
corresponding   to   one   year   and   calculate   and
display whether it is a leap year or not. (A year
is a leap year if it is a multiple  of 4, except
for   years   that   are   multiples   of   100     and   not
multiple of 400).

22.­   Do   the   program   that   computes   and   shows   the


perfect   numbers   less   than   1000.   (One   number   is
perfect   if   the   sum   of   its   divisors,   except   the
number itself, is equal to the number itself).

23.­   Do   the   Program   that   determines   if   two


positive   integers   are   friends.   (Two   numbers   are
friends   if   the   sum   of   the   divisors   of   the   first
one but itself is equal to the second one and vice
versa).

24.­   Do   the   program   that   enters   the   names   and


scores in SPL (Structured Programming Language) of
the   students   and   displays   the   number   of   failed
students   (<5),   passed   students   (<7),   significant
students (<8.5) and outstanding students (<= 10),
the   student   with  the  highest   score   and   the   one
with the lowest score and the average score of all
students.   The   collection   of   data   ends   when   you
enter the character “*” as a student’s name.

25.­ Do the program that enters  the names, gender
(M or F), salary (> 500 and <1000) and age (> 18
and <65>) of employees of a company. It must show
how many women earn less than 700 euros, and how
many men earn above 800 euros. Also it must show a
message   saying   if   there   is   any   woman   who   earns
over 900 euros.

26.­   Pepito   is   unhappy   with   his   performance   in


SPL.   In   his   first   program   he   made   a   mistake,   in
the   second   program   he   made   two   mistakes,   in   the
third one he made four and so on. In each program,
he always makes twice the number of mistakes than
in   the   previous   one.   The   course   lasts   thirteen

Programing
Course 2011/2012 Pág. 2
Department of Computer Science

weeks  and he must perform  two problems  per week.


You have to design the algorithm to calculate the
number of errors that Pepito is expected s to make
at the end of the course. 

27.­ Do the  program that displays the amount that
will be attributed to each winner of the Bonoloto.
You   have   to   introduce   the   following   information:
the   amount   to   be   distributed   and   the   number   of
winners in each category (3, 4, 5 and 6 hits). You
have to know that each category accounts for 10%,
20%,   30%   and   40%   of   the   total   amount   to   be
distributed.

28.­   The   ancient   philosopher   Zenon   is   known   for


its paradox of Achilles and the tortoise. This is
that   both   run   a   race   in   which   Achilles   runs   10
times   faster   than   the   tortoise,   but   the   tortoise
is   100   meters   ahead.   It   is   assumed,   in   the
paradox,   that   Achilles   will   never   reach   his
opponent   because   every   time   it   reaches   the   point
where   the   tortoise   was,   the   tortoise   will   have
moved   a   certain   distance.   You   have   to   design   an
algorithm to determine the time it takes Achilles
to reach, in fact, to the tortoise.

RECURSION

29.­   Do   the     program   that   inputs   an   integer   and


display the factorial of that number.

30.­ The Fibonacci series is a sequence of numbers
where each number is equal to the sum of the two
previous numbers. The first two numbers are 1. You
must   to   write   a   program   that   visualizes   the   nth
term of the Fibonacci series.

Programing
Course 2011/2012 Pág. 3

Potrebbero piacerti anche