i got an exercise in which i've to write a code that does:
when you enter the day of the
month (f.e. 21th) and the day (f.e. Sunday) and the month
(f.e. august) will display if in the given month there is a
13th Friday.
so i made a prog. that counts the days, it works, but even by my beginner standards the prog is too dumb and long, i made an if for every day of the week /i posted there only the if for sunday & monday, but it's all the same for the other days :( /
my question is, if there is a way to do it a bit more elegantly and shortly?
//calendar
#include <stdio.h>
#define s scanf
#define p printf
void main ()
{
int dw,dm,m;
p("plz enter dw, dm, m\n");
s("%d%d%d",&dw,&dm,&m);
//for Sundays
if (dw==1)
{
while (!(dm>=1&&dm<=7))
dm=dm-7;
if(dm==1)
p("in this month there is a 13th friday\n");
else
p("in this month there is no 13th friday\n");
}
//for mondays
if (dw==2)
{
while (!(dm>=1&&dm<=7))
dm=dm-7;
if(dm==2)
p("in this month there is a 13th friday\n");
else
p("in this month there is no 13th friday\n");
}
//and so on for the 7 days
}
thanx in advance