Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Algorithm :

1. Start.
2. Accept the date in the format
DD.MM.YYYY from the user.
3. Initialize variables `n` and `K` to zero.
4. Initialize arrays `b` with month numbers
and `c` with corresponding days in each
month.
5. Count the number of dots ('.') in the input
string to determine if it's a valid format.
6. If `K` is zero, print "invalid input" and
exit.
7. Tokenize the input string using '.' as the
delimiter.
8. Parse the tokens into integers for day,
month, and year and store them in variables
`day`, `month`, and `year`.
9. If the year is divisible by 4, update the
days in February to 29.
10. Check if the month is between 1 and 12
(inclusive).
11. If the day is within the valid range for
the given month, calculate the total number
of days passed in the year.
a. Iterate from month 1 to `month - 1`
(exclusive) and accumulate the days of
each month into `n`.
b. Add `day` to `n`.
12. Print the total number of days, i.e., "The
total day = [n]."
13. If any input is out of range, print "wrong
input." 14. End.
Listings:

Variable listing:

Variable Data purpose scope


name type
s String Store date accept()

n Int Store day accept()


K Int Count no. of accept()
dots
a[] String Store tokens accept()
day Int Store day accept()
month Int Store month accept()
year Int Store year accept()
b[] Int Store all month accept()
c[] Int Store all days accept()

Method Listing:
Method prototype purpose
name
accept() void accept() accept and
calculate all
data
main(String void create an
args[]) main(String instance and
args[]) callcreate an
instance and
call accept
Class listing:
Class name purpose
Days The main purpose of this
program is to calculate the
total number of dates
according to the given data

You might also like