Skip to content

Instantly share code, notes, and snippets.

@samueltcsantos
Created February 18, 2015 11:59
Show Gist options
  • 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
@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