Question 1:
1)
bool checkLeapYear(int year) {
return year % 4 == 0;
}
2)
int sumOfNumbers(int number) {
number--;
return number * (number + 1) / 2;
}
Question 2:
#include <stdio.h>
#include <stdbool.h>
#define MAX 50
char stack[MAX];
char queue[MAX];
int stackTop = -1;
int queueFront = 0;
int queueRear = 0;
void stackPush(char c) {
stackTop++;
stack[stackTop] = c;
}
char getStackTop() {
return stack[stackTop];
}
void stackPop() {
stack[stackTop] = '\0';
stackTop--;
}
bool stackEmpty() {
return stackTop == -1;
}
void queuePush(char c) {
queue[queueRear] = c;
queueRear++;
}
char getQueueFront() {
return queue[queueFront];
}
void queuePop() {
queue[queueFront] = '\0';
queueFront++;
}
bool isPalindrome(char string[MAX], int size) {
for (int i = 0; i < size; i++) {
stackPush(string[i]);
queuePush(string[i]);
}
while (!stackEmpty()) {
if (getStackTop() != getQueueFront())
return false;
stackPop();
queuePop();
}
return true;
}
comment down for any queries
please give a thumbs up
Assignment 1 Year 2 ICTEDU term 1 2019 For question 1 and 2 the report should...
[30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc Your task is to write a program that reads an input string prints that string, and then prints one of the following as appropriate: Is a Palindrome or Nota Palindrome I user response is input - racecar, the above program should print гacecar Is a Palindrome If user response is input = hello, the above program should print...
Write a function palcheck (char word II) which takes a C-style string word (or a C++ string word if you wish) and returns or false depending on whether or not the string is a palindrome. (A palindrome is a string which reads the same backwards and forwards. Some classic example of palindromes are radar, racecar, toot, deed, bib, civic, redder and madam.) Use your function from part (a) in a complete C++ program which, for each small letter 'a' through...
1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...
Complete task using python code From definitions file: month = ‘February’ year = 1200 Problem 2: Leap Years (2 Points) Your task is to write a program that takes in both a month and year (defined in the definitions file) and outputs the number of days for that month. It should take into account whether the year is a leap year or not. The resulting number of days in a given month/year combo is to be assigned to the variable...
Python Programming Task 2: Leap Years Part A - Is this a leap year? Write a function is leap year(year) that calculates whether a given (CE) year is a leap year. The function must: • take one argument: a positive integer representing a year (assumed to be CE) • return True if that year was a leap year; return False if not NOTE: all years that are divisible by four are leap years, unless they are also divisible by 100,...
Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....
Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should meet the following requirements: 1. The program shall graphically prompt the user for a file. 2. The program shall read the selected file which will contain 1 integer per line. 3. The program shall sort the values it reads from the file from largest to smallest. 4. The program shall write the values to an output file from largest to smallest in the same...
Background: For this assignment, you will write a small encryption utility that implements a simple encryption algorithm described below. The program will take one command line argument as an input; this will represent the word which is to be encrypted. As an output, your program will print the encrypted version of the word to the console using a simple printf() statement. This is the only output your program needs to produce. There is an important catch, however: your program is...