Self-hatred

Problem #19 non-solution

I’ve been having way too much fun with these:

using System;

public class Nineteen
{
	static void Main()
	{	
		
	}

	// Days in one month. Assumes "1-12" input.
	static int daysMonth(int year, int month)
	{
		int[]  a = new int[13] {0,31,28,31,30,31,30,31,31,30,31,30,31};
		int    b = 0;

		if ((leap(year)) && (month == 2))
			b = 29;
		else 
			b = a[month];

		return b;
	}


	// Days in one year period.
	static int days(int year)
	{
		int a = 0;

		if (!leap(year))
			a = 365;
		if (leap(year))
			a = 366;
			
		return a;
	}

	// Days in period. Inclusive.
	static int daysCen(int a, int b)
	{
		int c = 0;

		for (int i = a; i < = b; i++)
		{
			if (!leap(i))
				c += 365;
			if (leap(i))
				c += 366;
		}

		return c;
	}

	// Is the current year a leap year?
	static bool leap(int year)
	{
		bool a = false;

   	if (year % 400 == 0)
   		a = true;
   	else if (year % 100 == 0)
   		a = true;
   	else if (year % 4 == 0)
   		a = true;
   	else
   		a = false;

   	return a;
	}
}

Categorised as: programming


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>