-
-
Save samueltcsantos/b15eaae8dde4dff47fe6 to your computer and use it in GitHub Desktop.
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 |
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");
}
}
}
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();
}
}
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!")
Fiz de outra forma em PHP, esta aqui no meu github -> https://github.com/gilbertouk/PHP-Challenges/blob/main/challenge-21/challenge-21.php
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.
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;
}
}
}
}
Olá
Tenho uma duvida
Como é feito no portugol o algoritmo referente ao ano bissexto????
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
`
muito bem!
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
Eu fiz assim no Python 3.12.4:
Ano = int(input('Digite um ano: '))
Bissexto = Ano%4 == 0
if Bissexto:
print ('O ano é bissexto: ')
else:
print ('O ano não é bissexto: ')
Fiz para determinar se um determinado ano é bissexto em DART.
import 'dart:math';
class Leap {
bool leapYear(int year) {
bool status = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if ( year % 400 == 0 ) {
status = true;
} else {
status = false;
}
} else {
status = true;
}
} else {
status = false;
}
return status;
}
}
Em C++.
#include
#include <locale.h>
using namespace std;
int main(int argc, char** argv)
{
setlocale (LC_ALL,"");
}