Algorithms, Flowcharts and Applications for Figuring out Leap Years

Algorithms, Flowcharts and Applications for Figuring out Leap Years

Programming World – On this tutorial, I’ll focus on examples of algorithms, flowcharts and packages on the right way to decide leap years utilizing varied programming languages ​​starting from PHP, Python, C++ and Java.

For these of you who’re searching for an understanding of what algorithms and flowcharts are, you’ll be able to learn tutorials about algorithms and flowcharts on the programming world website.

Algorithms, Flowcharts and Applications for Figuring out Leap Years

Leap years are years which might be divisible by 4, and for brand new centuries akin to (…, 1900, 2000, 2100, and so forth.) are additionally divisible by 400. Earlier than we go into discussions about algorithms, flowcharts and instance packages utilizing varied programming languages, It will be good if we first understood what a intercalary year is.

This method was applied beginning in 1582, and is used as the premise for the Gregorian calendar which is at present utilized by many international locations, one in every of which is Indonesia. With this provision, then

  • 2008, 2016, 2024, … are leap years (not a brand new century, divisible by 4),

  • 1800, 2300, 2500, … aren’t leap years, as a result of they’re new centuries however aren’t divisible by 400,

  • 1200, 2400, 2800, … had been leap years which had been multiples of 400 and constituted a brand new century.

  • 20011, 2015, 2019, … aren’t leap years, as a result of they’re odd years.

That is just a little clarification about leap years, so mainly a intercalary year is a 12 months that’s divisible by 4 or 400.

Algorithm for Figuring out Leap Years

The next is an algorithm for figuring out leap years

  1. Begin
  2. Declare the 12 months variable
  3. Enter 12 months worth (greater than 0)
  4. Examine with the modulus to seek out out the rest of the quotient by 400
  5. If the modulus/remaining quotient of a 12 months with 400 is the same as 0 then it’s a intercalary year, if the modulus/remaining quotient of a 12 months with 100 is the same as 0 then it’s not a intercalary year, if the modulus/remaining quotient of a 12 months with 4 is the same as 0 then it’s a intercalary year, in any other case equals 0 then it’s not a intercalary year.
  6. Show Leap 12 months or Not Leap 12 months standing
  7. Completed

The method above is the method of discovering the standing of the quantity entered whether or not it’s a Leap 12 months or Not a Leap 12 months.

Subsequent, we are going to focus on how the flowchart seems to be like.

Flowchart Figuring out Leap Years

The next is an instance of a flowchart for figuring out leap years

Algorithms, Flowcharts and Programs for Determining Leap Years
Flowchart Figuring out Leap Years

If you wish to make flowcharts simply, you should use Microsoft Visio 2003, as a result of I normally use that model, however if you wish to use one other model, it is higher.

If you wish to obtain Microsoft Visio 2003, you’ll be able to click on the hyperlink right here.

Subsequent, we are going to enter this system creation stage ranging from PHP, Python, C++ and Java.

Program for Figuring out Leap Years

After the examples of algorithms and flowcharts for figuring out leap years have been mentioned, we are going to then transfer on to the tutorial on the right way to implement them in a program, whether or not in a PHP, Python, C++ or Java program.

Instance Program for Figuring out Leap Years Utilizing PHP

From the algorithm and flowchart that we created above relating to the right way to decide leap years, now we implement it into this system utilizing native PHP.




Figuring out Leap Years

Enter 12 months:


Save the code above with the title index.php into the xampp/htdocs/name_folder folder then take a look at it in your browser.

Instance Program for Figuring out Leap Years Utilizing Python

From the algorithm and flowchart that we created above relating to the right way to decide leap years, we now implement it right into a program utilizing Python.

print(“Enter 12 months : “) 12 months = int(enter()) if(12 months % 400 == 0): print(str(12 months) + ” is a intercalary year”) elif(12 months % 100 == 0): print (str(12 months) + ” shouldn’t be a intercalary year”) elif(12 months % 4 == 0): print(str(12 months) + ” is a intercalary year”) else: print(str(12 months) + ” shouldn’t be a intercalary year “)

Copy and paste the code above, then run it within the code editor that you simply normally use.

Instance Program for Figuring out Leap Years Utilizing C++

From the algorithm and flowchart that we created above relating to the right way to decide leap years, we now implement it right into a program utilizing C++.

#together with

utilizing namespace std; int foremost(){ int 12 months; cout< "Masukkan tahun: "; cin >> then; if (yrpercent400 == 0){ cout << yr << " Is a Leap Yearn"; } else if(yearpercent100 == 0){ cout << 12 months << "Not a Leap Yearn"; } else if(yearpercent4 == 0){ cout << 12 months << " Is a Leap Yearn"; } else { cout << 12 months << "Not a leap yearn"; } return 0; }

You copy and paste the code above, then run it with the C++ editor that you simply normally use.

Instance Program for Figuring out Leap Years Utilizing Java

From the algorithm and flowchart that we created above relating to the right way to decide leap years, we now implement it right into a program utilizing Java.

import java.util.*; public class LeapYear { public static void foremost(String[] args) { int 12 months; Scanner enter = new Scanner(System.in); System.out.print(“Enter 12 months: “); 12 months = enter.nextInt(); if (12 months % 400 == 0) { System.out.println(Integer.toString(12 months) + ” Is a intercalary year”); } else if (12 months % 100 == 0) { System.out.println(Integer.toString(12 months) + ” Not a intercalary year”); } else if (12 months % 4 == 0) { System.out.println(Integer.toString(12 months) + ” Is a intercalary year”); } else { System.out.println(Integer.toString(12 months) + ” Not a intercalary year”); } } }

That is my clarification in regards to the algorithm, flowchart and program for figuring out leap years utilizing the programming languages ​​PHP, Python, C++ and Java. If in case you have any questions, please write within the feedback column.

CATEGORIES
TAGS
Share This

COMMENTS

Wordpress (0)
Disqus ( )