Skip to content

Instantly share code, notes, and snippets.

@samueltcsantos
Created February 18, 2015 11:59
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samueltcsantos/b15eaae8dde4dff47fe6 to your computer and use it in GitHub Desktop.
Save samueltcsantos/b15eaae8dde4dff47fe6 to your computer and use it in GitHub Desktop.
Algoritmo para verificar se o ano é bissexto.
algoritmo "bissexto"
// Função : Bissexto - Um ano é bissexto se ele for divisível por 400 ou se ele
// for divisível por 4 e não por 100.
// Bissexto: 1980, 1984, 1988, 1992, 1996 e 2000.
// 1900 não foi bissexto, mas 1600 foi
// Autor : Samuel T. C. Santos
// Data : 18/02/2015
// Seção de Declarações
var
ano : inteiro
inicio
// Seção de Comandos
escreva("Ano? ")
leia(ano)
se (ano mod 400 = 0) ou ((ano mod 4 = 0) e (ano mod 100 <> 0)) entao
escreval(ano, " é bisexto!")
fimse
fimalgoritmo
@Rockafe
Copy link

Rockafe commented May 7, 2017

Em Python:
ano = int(input('Digite o ano: '))
if ano % 100 != 0 and ano % 4 == 0 or ano % 400 == 0:
print('É um ano bissexto')
else:
print('Não é bissexto')

@marcoa131
Copy link

Caso queira que o algoritmo diga se o ano também não for bisexto:

// Função : Define se um dado ano é bissexto - Um ano é bisssexto se ele for
// divisível por 400 ou se for divisível por 4 e não por 100
// Autor : marcoa131
// Data : 14/05/2017
// Seção de Declarações
var
ano : inteiro
inicio
// Seção de Comandos
escreval ("ano? ")
leia(ano)
se (ano mod 400 = 0) ou ((ano mod 4 = 0) e (ano mod 100 <> 0)) entao
escreval(ano, " é bisexto.")
senao entao
escreval (ano, " não é bisexto.")
fimse

fimalgoritmo

@dayannel
Copy link

dayannel commented Jun 4, 2018

Crie uma função que recebe um número inteiro como parâmetro, representando um ano, e retorna um valor lógico. A função deve retornar VERDADEIRO quando o ano for bissexto, e FALSO caso contrário. Um ano é bissexto se ele for divisível por 400; ou se ele for divisível por 4 e não por 100.

@WallaceMacedo
Copy link

#include <stdio.h>
#include <locale.h>

int main(void){
setlocale(LC_ALL,"Portuguese");
int ano;

int verifica(int ano);

printf("Digite um ano: "); scanf("%d",&ano);

if (verifica(ano) == 1)
printf("%d, ano bissexto!",ano);
else
printf("%d, não é ano bissexto!",ano);
return 0;
}

int verifica(int x){
if(x%400==0 || x%4==0 && x%100!=0)
return 1;
else
return 0;
}

@RubensZaes
Copy link

Em Kotlin:

fun main(args: Array) {
print("Digite um ano: ")
val ano = readLine()!!.toInt()

if ((ano % 4 == 0) && (ano % 100 != 0) || (ano % 400 == 0))
    print("${ano} é ano bissexto.")
else
    print("${ano} NÃO é ano bissexto.")

}

@GLuisF
Copy link

GLuisF commented Feb 28, 2020

Em Visual Basic:

Function Bissexto(Ano)
Bissexto = Ano Mod 4 = 0 And Ano Mod 100 > 0 Or Ano Mod 400 = 0
End Function

Retorna true se ano for bissexto

@euvictorguedes
Copy link

euvictorguedes commented May 25, 2020

Em JavaScript:

function anoBissexto(ano) {
  var bissexto = (ano % 4 == 0) && (ano % 100 != 0) || (ano % 400 == 0)
  console.log(bissexto)
}

Nessa função eu resolvi uma atividade para apenas retornar 1 ou 0.
1 se for (true) e 0 se não for (falso).

@Jean1979
Copy link

Jean1979 commented Jul 9, 2020

Olá

Tenho uma duvida

Como é feito em switch case o algoritmo referente ao ano bissexto????

@MasterTuto
Copy link

MasterTuto commented Oct 22, 2020

Olá

Tenho uma duvida

Como é feito em switch case o algoritmo referente ao ano bissexto????

Simplesmente não tem como, não faz sentido usar switch case aí. A não ser se tu fizer:

function ehBissexto(ano) {
    switch ( ( (ano % 4 == 0) && (ano % 100 != 0) ) || (ano % 400 == 0) ) {
        case (true):
             console.log("É bissexto");
             break;
        case (false):
            console.log("Não é bissexto");
            break;
    }
}

@danielcaze
Copy link

Em PHP:
$ano;
if (isset($_GET['ano'])) {
$ano = $_GET['ano'];
}
if (($ano % 100 != 0 && $ano % 4 == 0) || ($ano % 400 == 0)) {
echo "Esse ano é bissexto";
}
else {
echo "Esse ano não é bissexto";
}

@DaniloGalvan
Copy link

Em C#:
using System;

namespace ano_bisexto
{
class Program
{
static void Main(string[] args)
{
int ano;
bool bissexto;
Console.WriteLine("Digite um ano");
ano = int.Parse(Console.ReadLine());
if (ano % 400 == 0) {
bissexto = true;
}
else if ((ano % 4 == 0) && (ano % 100 != 0)) {
bissexto = true;
} else {
bissexto = false;
}

        if (bissexto == true) {
	        Console.WriteLine(ano + " é ano bissexto");
        } else {
	        Console.WriteLine(ano + " não é ano bissexto");
          }

@Alexis-Trainee
Copy link

Em ruby
puts "DIGITE UM ANO QUALQUER"
x = gets.chomp.to_i
puts "DIGITE UM ANO QUALQUER"
y = gets.chomp.to_i

while x<=y
if(x%4==0 or x%400==0)
puts x.to_s + " bissexto"
end
x+=1
end

@GuuhSantos939
Copy link

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

int main()
{
setlocale(LC_ALL,"Portuguese");
int ano;
printf("Digite o Ano q deseja consultar\n");
scanf("%i",&ano);
if (ano%400==0 || ano%4==0 && ano%100!=0){
printf("%i,é ano bissexto!",ano);
}else{
printf ("%i, não é ano bissexto!", ano);
}
return 0;
}

@Makley-Tibola-Trichez
Copy link

Makley-Tibola-Trichez commented Aug 13, 2021

Em PLpgSQL: (linguagem procedural do postgreSQL)

DO $$
DECLARE
	ano INT := 2020;  -- Aqui deve ser informado o ano
BEGIN
	IF MOD(ano, 400) = 0 OR (MOD(ano, 4) = 0 AND MOD(ano, 100) <> 0) THEN
		RAISE NOTICE 'É ano bissexto';
	ELSE
		RAISE NOTICE 'Não é ano bissexto';
	END IF;
END;
$$;

@Hemerson-Augusto
Copy link

Em C++.
#include
#include <locale.h>

using namespace std;

int main(int argc, char** argv)
{
setlocale (LC_ALL,"");

int ano;

cout<<"Digite o ano que deseja consultar: ";
cin>>ano;
	
if(ano % 400 == 0 || ano % 4 == 0 && ano % 100 != 0)
{
	cout<<"É ano bissexto: "<<ano;
}
else
{
	cout<<"Não é ano bissexto, operação invalida";
}
return 0;

}

@marcioauau2005
Copy link

marcioauau2005 commented Sep 21, 2021

package exercicio09;

//Verificar se o ano é bissexto.

import java.util.Scanner;

public class Exercicio09 {

public static void main(String[] args) {
           
    Scanner ler = new Scanner(System.in);
    
    System.out.printf("Informe informe o ano para verificar se é bissexto");
    
    int x;
    x = ler.nextInt();
    
    if (x% 4 == 0 || x% 400 == 0 || x% 100 == 0) {
        
        System.out.println("O ano "+ x +" é bissexto");
      
    }
    
    else {
    
       System.out.println("O ano "+ x +" não é bissexto");
   
   }
}

}

@danielgongo
Copy link

Em JAVA

import java.util.Scanner;

public class Ex17 {

public static void main(String[] args) {
	Scanner scan = new Scanner (System.in);
	
	System.out.print("Digite o ano: ");
	int ano = scan.nextInt();

	
	if (ano % 4 == 0) {
		System.out.println("Ano bissexto");
	}else {
		System.out.println("Não é um ano bissexto");
	}
	scan.close();
}

}

@ig0r-ferreira
Copy link

Olá, é possível realizar no python sem o uso de If e else?

def isleap(year:int):
    return year % 4 == 0 and year % 100 != 0 or year % 400 == 0

year = 2022
print(year, isleap(year) and "é" or "não é", "ano bissexto!")

@gilbertouk
Copy link

gilbertouk commented Sep 29, 2022

Fiz de outra forma em PHP, esta aqui no meu github -> https://github.com/gilbertouk/PHP-Challenges/blob/main/challenge-21/challenge-21.php

@Ruiperes02
Copy link

Verificar se um determinado ano, fornecido pelo utilizador, é bissexto. Um ano é bissexto se for divisível por 400 ou se for divisível por 4 e não for divisível por 100. Exemplos: 1988, 1992, 1996, 2000. Repare que 1900 não é bissexto.
Ajuda como fazer isto em C.

@vit0ur
Copy link

vit0ur commented Apr 10, 2023

Em C# esbocei três soluções possiveis aí fica a sua escolha qual utilizar

namespace Bissexto{
class ProgramBissexto{
static void Main(string[] args){

        Console.WriteLine("Digite o ano que deseja verificar se é bissexto: ");
        var ano = "";
        ano = Console.ReadLine();

/*SOLUÇÃO SECUNDARIA
if(Convert.ToInt32(ano)%4 == 0 && Convert.ToInt32(ano)%100 != 0 || Convert.ToInt32(ano)%400 == 0){
Console.WriteLine("O ano de "+ano+ " é bissexto");
}else{
Console.WriteLine("O ano de "+ano+" não é bissexto");
}
SOLUÇÃO TERCIARIA
if(DateTime.IsLeapYear(Convert.ToInt32(ano))){
Console.WriteLine("O ano informado é bissexto");
}
else{
Console.WriteLine("O ano informado NÃO é bissexto");
}
*/
switch ( Convert.ToInt32(ano) % 4 == 0 && Convert.ToInt32(ano) % 100 != 0 || Convert.ToInt32(ano) % 400 == 0 ) {
case (true):
Console.WriteLine(ano+" é bissexto");
break;
case (false):
Console.WriteLine(ano+" não é bissexto");
break;
}
}
}
}

@letxiz
Copy link

letxiz commented Aug 3, 2023

Olá

Tenho uma duvida

Como é feito no portugol o algoritmo referente ao ano bissexto????

@proccedure-caze
Copy link

proccedure-caze commented Aug 8, 2023

Olá

Tenho uma duvida

Como é feito no portugol o algoritmo referente ao ano bissexto????

// PORTUGOL

`
algoritmo "AnoBissexto"
var
ano: inteiro
inicio
escreva("Insira o ano que deseja verificar: ")
leia(ano)

se (ano mod 4 = 0) e ((ano mod 100 <> 0) ou (ano mod 400 = 0)) entao
escreva("O ano ", ano, " é bissexto.")
senao
escreva("O ano ", ano, " não é bissexto.")
fimse
fimalgoritmo
`

@zacarias19joel
Copy link

muito bem!

@Rogersorge
Copy link

Em Visual Basic:

Função Bissexto(Ano) Bissexto = Ano Mod 4 = 0 E Ano Mod 100 > 0 Ou Ano Mod 400 = 0 Função Final

Retorna true se ano for bissexto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment