In NI LabView. Write a VI that implements Zeller\'s congruence to find the day o
ID: 3108433 • Letter: I
Question
In NI LabView.
Write a VI that implements Zeller's congruence to find the day of the week for a given date. The front panel should have an input for the date mm/dd/yyyy and display the result as text, e.g., Thursday. The day of the week for a given Gregorian calendar date can be found using Zeller's congruence: day = mod(I, 7) where the modulo function mod(I, 7) equals the remainder when the integer I is divided by 7 and I is given by I = D + floor [2.6 (M + 1)] + Y + floor [Y/4] + floor [C/4] + 5C such that the floor[x] function rounds its arguments x to the closest lower integer. The quantities appearing in Zeller's congruence are defined as: day = day of the week (0 = Saturday, 1 = Sunday, ..., 6 = Friday) D = day of the month (3 = March, 4 = April, 5 = May, ..., 14 = February) M = month C = century given by floor (year, 100) Y = year within century given by mod (year, mod)Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
main()
{
char dt[11];
printf("enter date in mm/dd/yyyy ");
scanf("%s",dt);//in mm/dd/yyyy
int len=strlen(dt);
int **ch,i;
// ch array of 3*4 since maximum parameter of the 3 date is yyyy of size 4
ch=(int **)malloc(3*sizeof(int*));
for(i=0;i<4;i++)
{
ch[i]=(int *)malloc(4*sizeof(int));
}
int j=0,count=0;
for(i=0;i<len;)
{
if(dt[i]!='/'&&j<2&&count<2) //first two characters for date and month marked zero since array is of size 4
{
ch[count][j]=0;
j++;
}
else if(dt[i]=='/')
{
count++;
j=0;
i++;
}
else
{
ch[count][j]=dt[i]-48;
j++;
i++;
}
}
//dayCal,monthCal,yearCal correspond to input date(dd) month(mm) and year(yyyy)
int dayCal=0;
int monthCal=0;
int yearCal=0;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(i==0&&j>=2)
monthCal = monthCal*10+ch[i][j];
if(i==1&&j>=2)
dayCal = dayCal*10+ch[i][j];
if(i==2)
yearCal=yearCal*10 + ch[i][j];
}
}
// printf("%d %d %d",dayCal,monthCal,yearCal);
int C = yearCal%100; //century
int Y = yearCal;
int D;
if(monthCal==1)
D=13; //January D=13
else if(monthCal==2)
D=14;//February D=14
else
D=monthCal;
int M=monthCal;
double k1=2.6*(M+1);
int im = (int)k1; // equivalent to floor
int k2= Y/4; //equivalent to floor(Y/4)
int k3 =C/4; // equivalent to floor(C/4)
int I = D + im + Y + k2 + k3 + 5*C;
int day = I%7;
switch(day)
{
case 0:
printf("saturday");
break;
case 1:
printf("Sunday");
break;
case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
default:
printf("none");
}
// system("Pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.