In: Computer Science
Using C language, and describe the algorithm
design
All the sample is correct
Tim was born in a leap year, so he would like to know when he could have his birthday party. Could you tell him? Given a positive integers Y indicating the starting year, and a positive integer N, your task is to tell the N-th leap year from year Y. Note: if year Y is a leap year, then the 1st leap year is year Y.
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains two positive integers Y and N(1<=N<=10000). For each test case, you should output the Nth leap year from year Y.
3
2005 25
1855 12
2004 10000
2108
1904
43236
PLEASE UPVOTE IF THIS ANSWER SEEMS HELPFUL AS IT GIVES THE CONFIDENCE TO HELP MORE STUDENTS
THANKYOU
**************************************************************************************************************
NB: I think there is a mistake in your third sample output please verify that.
********************************************************************************************************
#include<stdio.h>
#include <stdbool.h>
bool checkYear(int year)
{
// If a year is multiple of 400,
// then it is a leap year
if (year % 400 == 0)
return true;
// Else If a year is muliplt of 100,
// then it is not a leap year
if (year % 100 == 0)
return false;
// Else If a year is muliplt of 4,
// then it is a leap year
if (year % 4 == 0)
return true;
return false;
}
int main() {
int T,i,t;
// printf("Enter the value of T: ");
scanf("%d",&T);
int arr[T][2];
int ans[T];
// printf("Enter y and N \n");
for(i=0;i<T;i++)
{
scanf("%d %d",&arr[i][0],&arr[i][1]);
if(checkYear(arr[i][0]))
{
t = arr[i][0] + (arr[i][1]-1)*4 ;
ans[i] = t;
}
else if(checkYear(arr[i][0]+1))
{
t = arr[i][0] + 1 + (arr[i][1])*4 ;
ans[i] = t;
}
else if(checkYear(arr[i][0]+2))
{
t = arr[i][0] + 2 + (arr[i][1])*4 ;
ans[i] = t;
}
else
{
t = arr[i][0] + 3 + (arr[i][1])*4 ;
ans[i] = t;
}
}
for(i=0;i<T;i++)
{
// printf("N-th leap year from year mentioned are:\n");
printf("%d\n",ans[i]);
}
}
OUTPUT