Advertisement
Guest User

CALCULADORA DIAS

a guest
Oct 22nd, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Aula_22_10_2014
  8. {
  9.     class Program
  10.     {
  11.         static int Ano_Bissexto(int x)
  12.         {
  13.             if (x % 4 == 0 && x % 100 != 0)
  14.             {
  15.                 x = 1;
  16.                 return x;
  17.             }
  18.             else
  19.             {
  20.                 if (x % 400 == 0)
  21.                 {
  22.                     x = 1;
  23.                     return x;
  24.                 }
  25.                 else
  26.                 {
  27.                     x = 0;
  28.                     return x;
  29.                 }
  30.             }
  31.         }
  32.         static int Calculadora_Dias( int diax,  int mes,  int ano)
  33.         {            
  34.             int[] dia_meses = new int [13];
  35.             dia_meses[1] = 31;
  36.             dia_meses[2] = 28 + Ano_Bissexto(ano);
  37.             dia_meses[3] = 31;
  38.             dia_meses[4] = 30;
  39.             dia_meses[5] = 31;
  40.             dia_meses[6] = 30;
  41.             dia_meses[7] = 31;
  42.             dia_meses[8] = 31;
  43.             dia_meses[9] = 30;
  44.             dia_meses[10] = 31;
  45.             dia_meses[11] = 30;
  46.             dia_meses[12] = 31;
  47.             for (int i = 1; i <= mes; i++)
  48.             {
  49.                 diax = diax + dia_meses[i];
  50.             }              
  51.             return diax-dia_meses[mes];
  52.         }
  53.         static void Main(string[] args)
  54.         {
  55.             int repetir = 1;
  56.             do
  57.             {
  58.                 int dia = 0, mes = 0, ano = 0, dias = 0;
  59.                 Console.Write("Digite o dia:        ");
  60.                 dia = Int16.Parse(Console.ReadLine());
  61.                 Console.Write("Digite o mês:        ");
  62.                 mes = Int16.Parse(Console.ReadLine());
  63.                 Console.Write("Digite o ano:        ");
  64.                 ano = Int16.Parse(Console.ReadLine());
  65.                 dias = Calculadora_Dias(dia, mes, ano);
  66.                 Console.WriteLine("\nData:\t{0}/{1}/{2}\nNúmero de dias:\t{3}", dia, mes, ano, dias);
  67.                 Console.WriteLine("\n\aFaltam {0} dias para o ano acabar!", (365 + Ano_Bissexto(ano)) - dias);
  68.                 Console.Write("\nDeseja tentar outra data? 1 para sim, 0 para não: ");
  69.                 repetir = Int16.Parse(Console.ReadLine());
  70.                 Console.Clear();
  71.             } while (repetir == 1);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement