Question

In: Computer Science

Using C language, and describe the algorithm design All the sample is correct Q3 Problem description...

Using C language, and describe the algorithm design
All the sample is correct

  • Q3 Problem description

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.

  • Input & output requirements

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.

  • Sample input

3

2005 25

1855 12

2004 10000

  • Sample output

2108

1904

43236

Solutions

Expert Solution

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


Related Solutions

Using C language, and describe the algorithm design Q2 Problem description n (n is odd) people...
Using C language, and describe the algorithm design Q2 Problem description n (n is odd) people sitting around a round table playing a game. In this situation, everyone has a left neighbour and a right neighbour. At the beginning, each of them is holding a whiteboard with an integer number. Now, they are playing a game consisting of several rounds. In each round, everyone will first look at the numbers of his/her left neighbour and right neighbour, then calculate the...
How to make this problem? in C language Build an algorithm that, upon receiving as input...
How to make this problem? in C language Build an algorithm that, upon receiving as input the ID and salary of the professors of a university, determines the following: -Total payroll of teachers. -The average salaries of teachers. -ID of the employee with the highest salary as well as what's his salary thanks
Using C language Problem description n (n is odd) people sitting around a round table playing...
Using C language Problem description n (n is odd) people sitting around a round table playing a game. In this situation, everyone has a left neighbour and a right neighbour. At the beginning, each of them is holding a whiteboard with an integer number. Now, they are playing a game consisting of several rounds. In each round, everyone will first look at the numbers of his/her left neighbour and right neighbour, then calculate the average of the two numbers, replace...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it needs to include time and space complexities of this algorithm. There is a matrix (N times N) of integers which rows and columns are sorted in non-decreasing order. A sorted matrix and integer M will be given and we need to find the position(row,column) of M in this matrix. it's okay to report only one position if there are more than one answers. when...
Problem: Design and write a C language program that can be used as a unit converter...
Problem: Design and write a C language program that can be used as a unit converter application. Your unit converter should contain at least four unit categories, for example: length, mass, temperature, and time. The program should display the main menu that contains unit categories that are available, and the user will be prompted to select a unit category first. After the unit category has been selected the program should then display another menu (i.e., a submenu) that contains at...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is...
Problem 2. Purpose: practice algorithm design using dynamic programming. A subsequence is palindromic if it is the same whether read left to right or right to left. For instance, the sequence A,C,G,T,G,T,C,A,A,A,A,T,C,G has many palindromic subsequences, including A,C,G,C,A and A,A,A,A (on the other hand, the subsequence A,C,T is not palindromic). Assume you are given a sequence x[1...n] of characters. Denote L(i,j) the length of the longest palindrome in the substring x[i,...,j]. The goal of the Maximum Palindromic Subsequence Problem (MPSP)...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students...
Problem: Make linkedList.h and linkList.c in Programming C language Project description This project will require students to generate a linked list of playing card based on data read from a file and to write out the end result to a file. linkedList.h Create a header file name linkedList Include the following C header files: stdio.h stdlib.h string.h Create the following macros: TRUE 1 FACES 13 SUITS 4 Add the following function prototypes: addCard displayCards readDataFile writeDataFile Add a typedef struct...
Use C language Problem 1: Buy cheese (Level 1) • Problem description You have M dollors...
Use C language Problem 1: Buy cheese (Level 1) • Problem description You have M dollors and want to buy as much cheese as possible. There is a cheese shop with two kinds of cheese. The unit prices of the both cheese are p1 and p2, the total amount of them are a1 and a2. You can buy either cheese or both, but the amount you buy cannot exceed its total amount. Write a program to output the largest amount...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language...
Description: In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string. The alphabet for generating DNA sequences is {A, T, G, C}. Write a regular expression that represents all DNA strings that begin with ‘A’ and end with ‘T’. Note: assume empty string is not a valid string. Design a deterministic finite automaton to recognize the regular expression. Write a program which...
Please answer both the questions. 1 a) Design two bits comparators using Verilog description language Note:...
Please answer both the questions. 1 a) Design two bits comparators using Verilog description language Note: Design means RTL code and Testbench covering all possible corner cases) b) How many latches will result when the following code is synthesized? Assume B is 4-bits long.                                always@(state)                                begin                                         case(state)                                       2’b00: B = 5;                                          2’b01: B = 3;                                       2’b10: B = 0;                                         endcase                                end
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT