💻 Ingresar la fecha actual y mostrar el número total de días transcurridos desde el inicio de este año, considerando que todos los meses tienen 30 días.
En este caso se puede tomar como referencia que todos los meses tienen 30 días, de está manera cuando se ingresa el número del mes se multiplica por 30 y adicional mente se le suma los días. Los meses son desde el 1 al 12; si se ingresa como mes el número 2 podemos restarle a cada ingreso de mes menos 1 y luego multiplicarlo por 30 para luego sumarlos con los días..
Por ejemplo : MES = 2, DIAS = 5
TIEMPO : ( (MES – 1) * 30 ) + DIAS
TIEMPO : ( (2 – 1) * 30 ) + 5
TIEMPO : ( 1 * 30 ) + 5
TIEMPO : 35
También te puede interesar más ejercicios con fechas :
Algoritmo programacion_work
Definir Mes, Dia, Tiempo como Entero;
Escribir "MOSTRAR LOS DÍAS TRANSCURRIDOS DESDE EL INICIO DEL AÑO.";
Escribir " ";
Escribir Sin Saltar "Ingrese Número de Mes : ";
Leer Mes;
Escribir Sin Saltar "Ingrese Número de Día : ";
Leer Dia;
Tiempo <- (((Mes - 1) * 30) + Dia);
Escribir " ";
Escribir "Días Transcurridos : ", Tiempo;
FinAlgoritmo
print("MOSTRAR LOS DÍAS TRANSCURRIDOS DESDE EL INICIO DEL AÑO.")
mes = int(input("Ingrese Número de Mes : "))
dia = int(input("Ingrese Número de Día : "))
tiempo = (((mes-1)*30)+dia)
print("Días Transcurridos : ",tiempo)
#include<stdio.h>
int main() {
int dia, mes, tiempo;
printf("MOSTRAR LOS DIAS TRANSCURRIDOS DESDE UNA FECHA DADA.\n\n");
printf("Ingrese Numero de Mes : ");
scanf("%i",&mes);
printf("Ingrese Numero de Dia : ");
scanf("%i",&dia);
tiempo = (((mes-1)*30)+dia);
printf("\nDias Transcurridos : %i Dias.\n",tiempo);
return 0;
}
#include<iostream>
using namespace std;
int main() {
int dia, mes, tiempo;
cout << "MOSTRAR LOS DIAS TRANSCURRIDOS DESDE UNA FECHA DADA.\n\n";
cout << "Ingrese Numero de Mes : ";
cin >> mes;
cout << "Ingrese Numero de Dia : ";
cin >> dia;
tiempo = (((mes-1)*30)+dia);
cout << "\nDias Transcurridos : " << tiempo << " Dias." << endl;
return 0;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
class dias_transurridos
{
static void Main(string[] args)
{
int dia, mes, tiempo;
Console.WriteLine("MOSTRAR LOS DIAS TRANSCURRIDOS DESDE UNA FECHA DADA.\n");
Console.Write("Ingrese Numero de Mes : ");
mes = int.Parse(Console.ReadLine());
Console.Write("Ingrese Numero de Dia : ");
dia = int.Parse(Console.ReadLine());
tiempo = (((mes - 1) * 30) + dia);
Console.WriteLine("\nDias Transcurridos : " + tiempo + " Dias.");
Console.ReadLine();
}
}
}
package programacion_work;
import java.util.Scanner;
public class dias_transcurridos {
public static void main(String[] args) {
Scanner ingreso=new Scanner(System.in);
int DIA, MES, TIEMPO;
System.out.print("MOSTRAR LOS DÍAS QUE HAN PASADO DESDE EL INICIO DEL AÑO.\n\n");
System.out.print("Ingrese Nro Mes : ");
MES = Integer.parseInt(ingreso.next());
System.out.print("Ingrese Nro Día : ");
DIA = Integer.parseInt(ingreso.next());
TIEMPO = ((MES - 1)*30)+DIA;
System.out.println("DÍAS TRANSCURRIDOS: " + TIEMPO + " DÍAS");
}
}
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {
int DIA, MES, TIEMPO;
DIA = Integer.parseInt(jTxt_Dias.getText());
MES = Integer.parseInt(jTxt_Meses.getText());
TIEMPO = ((MES - 1)*30)+DIA;
jTxt_Tiempo.setText(String.valueOf(TIEMPO));
}
Imports System.Console
Module total_de_dias
Dim Dia, Mes, Tiempo As Integer
Sub Main()
WriteLine("12. MOSTRAR LOS DÍAS TRANSCURRIDOS DESDE EL INICIO DEL AÑO")
WriteLine("")
Write("Ingrese Mes: ")
Mes = ReadLine()
Write("Ingrese Día : ")
Dia = ReadLine()
WriteLine("")
Tiempo = ((Mes - 1) * 30) + Dia
WriteLine("Total de Dias : " & Tiempo)
ReadLine()
End Sub
End Module
Private Sub Btn_Calcular_Click(sender As Object, e As EventArgs) Handles Btn_Calcular.Click
Dim Dia, Mes, Tiempo As Integer
Mes = Txt_Mes.Text
Dia = Txt_Dia.Text
Tiempo = ((Mes - 1) * 30) + Dia
Txt_Total_Dias.Text = Tiempo
End Sub
Sub Total_Dias2()
Dim Mes As Integer
Dim Dia As Integer
Dim Tiempo As Integer
Mes = Range("C12").Value
Dia = Range("D12").Value
Tiempo = (((Mes - 1) * 30) + Dia)
Range("G12").Value = Round(Tiempo, 2)
End Sub
Sub Total_Dias()
Dim Mes As Integer
Dim Dia As Integer
Dim Tiempo As Integer
Mes = InputBox("INGRESE MES")
Dia = InputBox("INGRESE DIA")
Tiempo = (((Mes - 1) * 30) + Dia)
MsgBox "Total de Días : " & Tiempo
End Sub
Private Sub btn_calcular_Click()
Dim Mes As Integer
Dim Dia As Integer
Dim Tiempo As Integer
Mes = txt_mes.Text
Dia = txt_dia.Text
Tiempo = (((Mes - 1) * 30) + Dia)
txt_total_dias.Text = Tiempo
End Sub