Programming Assignment 2

Prob1. In the Gregorian calendar, which is the calendar used by most modern countries, the following rules decides which years are leap years:

  1. Every year divisible by 4 is a leap year.
  2. But every year divisible by 100 is NOT a leap year
  3. Unless the year is also divisible by 400, then it is still a leap year.
Write a program that verifies if an input is a valid date (taking care of leap years). For example 29 2 1997 is not a valid date, but 29 2 2004 is valid.

Reading assignment: Read about the "switch" instruction in C and design a solution based on it.

Prob 2. The following program calculates i raised to power k.

#include <stdio.h>
                                                                                
int i, j, ans, k;
                                                                                
main ()
{
  printf("Supply number (+ve integer) and exponent(+ve integer) \n");
  scanf("%d %d",&i,&k);
  printf("%d\n",k);
     ans = 1; /* initialization*/
      j = k;
     while (j >= 1)
    {
      ans = ans*i ;
      j = j - 1;
                                                                                
    }
   printf("%d raised to %d is %d\n", i, k, ans);
                                                                                
}

(i) Modify this program so that it can handle non-positive integers also.

(ii) Enhance the capability of the program such that given a 2 by 2 matrix, A it can compute A raised to a (non-negative) integer. You can choose any convention for the input/output format of the matrix.