-
-
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 |
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
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.
#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;
}
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.")
}
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
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).
Olá
Tenho uma duvida
Como é feito em switch case o algoritmo referente ao ano bissexto????
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;
}
}
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";
}
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");
}
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
#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;
}
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;
$$;
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;
}
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: ')
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')