Zeller's Congruence Algorithm in C.

Zeller's Congruence is an algorithm devised by Christian Zeller to calculate the day of the week for any date. The algorithm provides a simple and efficient way to determine the weekday for any date in the Gregorian calendar. 

The formula for Zeller's Congruence is given by:
Zeller's Congruence Algorithm
Where:
  • h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ..., 6 = Friday)
  • q is the day of the month
  • m is the month (3 = March, 4 = April, ..., 14 = February)
  • K is the year of the century (i.e., year mod 100)
  • J is the zero-based century (actually ⌊ year/100 ⌋)
The result h corresponds to the days of the week, where 0 is Saturday, 1 is Sunday, and so on.

Here's a breakdown of the formula:
  • The term 13(+1)5 adjusts for the months (January and February are counted as months 13 and 14 of the previous year).
  • +4 takes care of the year part.
  • 42 deals with the century adjustment.

Example: Let's calculate the day of the week for March 1, 2023.
Calculation of the day of the week for March 1, 2023
After calculation, we got h value equal to 4 which means March 1, 2023, is Thursday.

C program Implementation of Zeller's Congruence.

// C program to find day of the week for a Date
// Zeller's Congruence
#include <stdio.h>

int zellersCongruence(int day, int month, int year) {
    if (month < 3) {
        month += 12;
        year--;
    }

    int K = year % 100;
    int J = year / 100;

    int h = (day + (13 * (month + 1)) / 5 + K + K / 4 + J / 4 - 2 * J) % 7;

    // Convert h to a more conventional form 
    // (0 = Saturday, 1 = Sunday, ..., 6 = Friday)
    return h % 7;
}

int main() {
    int day = 1, month = 3, year = 2023;

    int dayOfWeek = zellersCongruence(day, month, year);
    char arr[7][10] = {"Saturday", "Sunday", "Monday", 
                       "Tuesday", "Wednesday", "Thursday", "Friday"};
    
    printf("March 1, 2023 is a %s", arr[dayOfWeek]);
    
    return 0;
}
Output:
March 1, 2023 is a Wednesday

In this C program, the zellersCongruence function calculates the day of the week using Zeller's Congruence, and the result is then displayed in a user-friendly format. 

Quick Response (QR) Code: Definition and Working of QR Code.

Quick Response Code which is popularly known as QR Code has become part of our daily life so quickly in just a couple of years. This technology is quite old but now we use it everywhere for various purposes like making online payments, getting product details from packages, sharing event tickets, and more. Let's learn more about QR codes and how they work.

How Quick Response Code (QR Code) Work

What is a Quick Response (QR) Code?

A Quick Response (QR) code is a two-dimensional barcode that can store various data types, including text, URLs, contact information, and more. A scanning device such as a smartphone camera or dedicated barcode scanner is used to read the information stored in a QR code. 

It was first developed in 1994 by a Japanese company called Denso Wave, which is a subsidiary of Toyota. QR codes gained popularity due to their ability to store more information than traditional barcodes and their quick readability.


How does Quick Response (QR) Code Work?

QR, or Quick Response, codes are two-dimensional barcodes that store information in a matrix pattern of black squares on a white background. The process begins with data encoding, where the desired information, such as a URL or text, is translated into a matrix structure.

To generate a QR code, we use QR code generators, which can be standalone applications, features within mobile apps, or online tools. We input the data and configure settings like error correction levels and size, and the generator transforms this information into a distinctive black-and-white pattern.

We can print the generated QR code on paper, or we can display it on a digital screen or physical media. We position our scanning device to capture the QR code and the image undergoes processing to identify the black square pattern. 

The decoding software then interprets the QR code pattern as binary data. The binary data, representing the original information, is then converted back into its original form.

The final stage involves the action or display of the decoded information. The user may be directed to a website, presented with text, or prompted to perform a transaction, depending on the nature of the encoded data. 
Note: QR codes often integrate error correction mechanisms. These mechanisms enable the reconstruction of data even if parts of the code are damaged or obscured during the scanning process. This robustness is especially useful for maintaining functionality in less-than-ideal scanning conditions. (alert-passed)


Difference Between Quick Response Code and Barcode.

QR code is basically the advanced version of a barcode but still, there are many differences between them, and here we have listed a few.

QR Code Barcode
Can store various types of data, including alphanumeric characters, binary data, and special characters. Primarily encodes numeric or alphanumeric characters.
Higher data capacity, suitable for storing large amounts of information. Limited data capacity, generally used for smaller sets of data.
2D (two-dimensional) matrix code that can store data both horizontally and vertically. 1D (one-dimensional) linear code with data encoded in parallel lines.
Versatile in terms of the types of data it can store, making it suitable for diverse applications. Limited versatility, primarily used for simple identification purposes.
Built-in error correction capabilities, allowing for data recovery even if parts of the code are damaged Generally lacks robust error correction features.
ISO standardized (ISO/IEC 18004), ensuring consistency and compatibility. Multiple standards (such as UPC and EAN) depending on the type of barcode.

Types of Quick Response (QR) Codes.

There are various types of QR codes available in the market and each of them has their own feature and use case. These are:
  • Micro QR Code: This is a smaller version of the standard QR code suitable for applications with limited space, such as small product labels and packaging.
  • Frame QR Code: It has a distinct frame or border around the QR code and they are commonly used in marketing and advertisements, allowing for creative designs.
  • Kanji QR Code: Kanji QR code is Optimized for encoding Kanji characters. It is commonly used in Japan for applications involving Kanji characters.
  • Model 1 QR Code: Model 1 QR Code is characterized by a simple structure that comprises a single row for encoding data. It does not have the usual 2D matrix structure found in standard QR codes.
  • IQR QR Code (SQRC): It has a unique square shape introduced by Denso Wave. Suitable for applications where a square QR code is preferred, offering increased data capacity.

Usage of Quick Response (QR) Code.

QR code has become an integral part of modern life offering a quick and convenient way to share information with a simple scan. Here we have listed some use cases of QR code.
  • Mobile Payments: QR codes facilitate mobile payments, allowing users to make transactions by scanning a code generated by a payment app.
  • Product Information: QR codes on product packaging can provide consumers with additional information, such as user manuals or promotional content.
  • Marketing and Advertising: QR codes are used in marketing materials to direct users to websites, promotions, or multimedia content.
  • Event Ticketing: QR codes on tickets streamline entry to events by allowing attendees to scan their tickets at checkpoints.
  • Contactless Menus: In the hospitality industry, QR codes on tables provide diners with access to digital menus using their smartphones.
  • Product Packaging: Manufacturers include QR codes on product packaging for easy access to user manuals, warranty information, or promotional content.
  • Authentication and Security: QR codes are used for two-factor authentication. Apps generate dynamic QR codes for secure login processes.

QR codes continue to evolve, finding innovative applications across industries, making them an essential tool for information access and engagement in the digital age.

QR Code: FAQs.

Q1. What Information Can a QR Code Store?
Answer: QR codes can store a variety of data types, including website URLs, contact information (vCards), text, calendar events, Wi-Fi network credentials, and more.

Q2: Are QR Codes Secure?
Answer: QR codes themselves are not inherently secure or insecure. The security depends on the content they link to. Users should be cautious and avoid scanning QR codes from untrusted or suspicious sources.

Q3: Do QR Codes Expire?
Answer: QR codes themselves do not have an expiration date. However, the content they link to, such as a website or promotion, may have a time limit or expiration.

Related Article:

How To Scan QR Code on Windows Laptop.

Scan QR Code on Laptop

A QR code, or Quick Response code, is a two-dimensional barcode that can store data, such as text or a web link, in a matrix of black squares arranged on a white background. We all usually use our phones to scan any QR Code but it becomes a challenging task when we have to scan QR on our laptop. 

In this guide, we will learn how to scan a QR code on our Windows laptop using our laptop camera and Google Lens. 

Scan QR Code Using Windows Camera App.

We typically use Windows cameras to take photos and videos but now Microsoft has added an additional feature to scan QR codes as well.

Click on the Windows button on the keyboard and search for the "Camera" app in the menu. In the latest update on Windows, they have added a barcode scan button just below the button that we use to take photos.  

Windows Camera app to Scan QR

If you do not see this feature on a Windows laptop then it might be possible that you are using an older version of Windows 11. 

To enable this feature on older versions, click on the gear icon in the top left corner and open "Related Settings" to enable the toggle button of "Try out new experimental features." Restart the Camera app to get the barcode icon.

Scan QR Code on Windows Laptop.

Now place your QR code in front of the camera and it will scan it automatically.

Scan the QR Code Using Google Lens.

You can also use the Google image search feature that is available in the Google Chrome browser to scan a QR Code.

In the Chrome browser, right-click on the QR image you want to scan and click on the "search image with Google" option. 

Chrome Browser in Laptop to scan QR

You will see that a Google Lens side is open in our browser itself providing all the details about the QR code. It will show the attached link present inside the QR with a direct link to visit the website. 

Scan QR Code in Google Lens Chrome Browser

These are the two methods by which you can scan QR on any Windows laptop. You can also easily generate a QR code for any page in Chrome browser just by right-clicking and then choosing "Create QR Code for this Page".

Nouns, Types of Nouns and Examples.

Nouns are a very important part of any sentence and this is one of those early topics that we always learn while learning English Grammar. Out of all eight parts of speech, noun is the first parts of speech that we will learn in this section with examples.

Nouns are words that name people, places, things, or ideas. They are the building blocks of sentences, giving us specific names for the people we know, the places we go, the things we use, and the ideas we think about. Nouns help us express the who, what, and where in our everyday language.

Some Noun Examples in Sentences:
  • sun: The sun is shining brightly in the clear blue sky.
  • sister: My sister brought a delicious cake for the celebration.
  • mountain: The mountain range had a majestic appearance at sunrise.
  • cat: The curious cat climbed the tall tree with agility.
  • concert: The concert was a mesmerizing experience for the audience.

In these sentences, nouns such as "sun," "sister," "cake," "mountain range," "cat," and "concert" name specific entities, adding detail and specificity to the statements.

Types of Nouns.

There are eight types of nouns present and each has its own role in any English sentence. Here we will learn some of the common types of nouns that are used in our daily life communication.

Types of Nouns Examples
Common Nouns dog, city, car
Proper Nouns John, Paris, Toyota
Countable Nouns book, chair, cat
Uncountable Nouns water, air, advice
Concrete Nouns table, tree, laptop
Abstract Nouns love, courage, happiness
Collective Nouns team, family, herd
Compound Nouns toothpaste, basketball, postman

1. Common Nouns: Common nouns are general names for people, places, things, or ideas. They represent categories rather than specific, unique entities. Common nouns are not capitalized unless they appear at the beginning of a sentence.

Examples of Common Nouns in Sentences.

  • dog: The friendly dog wagged its tail as we approached.
  • city: I love the vibrant atmosphere of the bustling city at night.
  • book: She found an interesting book at the library and couldn't put it down.
  • teacher: The dedicated teacher inspired her students to pursue their passions.
  • car: The sleek red car zoomed down the highway, turning heads.
  • river: We enjoyed a peaceful picnic by the flowing river.
  • computer: His new computer allowed him to work more efficiently.
  • school: The children eagerly headed to the school playground during recess.
  • friend: A true friend is someone who stands by you in both good and bad times.
  • happiness: Finding moments of simple joy brings a sense of profound happiness.

2. Proper Nouns: Proper nouns are specific names given to individual people, places, or things. They are always capitalized, distinguishing them from common nouns which are general and not capitalized.

Examples of Proper Nouns in Sentences.

  • Max: Max is an energetic Golden Retriever who loves to play fetch.
  • Paris: We spent a week exploring the charming streets of Paris.
  • Harry Potter: Harry Potter is a famous character in J.K. Rowling's novels.
  • Amazon: I ordered a new book from Amazon for my collection.
  • Mount Everest: Climbing Mount Everest is a challenging but rewarding experience.
  • The Eiffel Tower: Tourists from around the world visit The Eiffel Tower in Paris.
  • Coca-Cola: Coca-Cola is a popular beverage enjoyed globally.
  • June: We are planning a family vacation in June.
  • United Nations: The United Nations works towards global peace and cooperation.
  • Mona Lisa: The mysterious smile of the Mona Lisa captivates art enthusiasts.

3. Concrete Nouns: Concrete nouns refer to tangible, physical entities that can be perceived through the senses. These nouns represent objects that occupy space and have a clear existence.

Examples of Concrete Nouns in Sentences.

  • desk: The old oak desk in the study has been in our family for generations.
  • Chocolate: Chocolate is her favorite treat, especially the dark and rich varieties.
  • car: The shiny red car caught everyone's attention as it sped down the street.
  • balloons: Children played in the soft, green grass of the park, giggling with joy at the colorful balloons.
  • river: The crystal-clear river flowed gently, reflecting the beauty of the surrounding nature.
  • vase: He carefully placed the delicate vase on a table, filled with vibrant flowers.
  • bread: The aroma of freshly baked bread wafted through the air, enticing everyone in the neighborhood.
  • stars: We gazed at the starry night sky, mesmerized by the vastness of the universe and the twinkling stars.

4. Abstract Nouns: Abstract nouns are words that represent intangible, conceptual, or non-physical entities. They refer to things that cannot be perceived through the senses but are experienced emotionally, mentally, or conceptually. Abstract nouns often denote feelings, qualities, states, concepts, or ideas.

Examples of Abstract Nouns in Sentences.

  • Love: Their love for each other was evident in every gesture and glance.
  • Courage: Despite the danger, he faced the challenge with great courage.
  • Happiness: The birth of their child brought immense happiness to the family.
  • Intelligence: Her intelligence and problem-solving skills made her an invaluable team member.
  • Justice: The pursuit of justice is a fundamental principle in a fair society.
  • Freedom: The struggle for freedom has been a long and challenging journey.
  • Wisdom: Old age often brings not just wrinkles but also wisdom.

5. Countable Nouns: Countable nouns are objects, people, things, or concepts that can be counted and have a plural form. These nouns can be expressed in both singular and plural forms, and we can use numbers before them to quantify or count them. Countable nouns can be both concrete (tangible) and abstract (intangible).

Examples of Countable Nouns in Sentences.

  • Dog: They have adopted two dogs from the shelter.
  • Book: She bought three books for her summer reading list.
  • Car: In the parking lot, there are several cars of different colors.
  • Student: The teacher asked the students to submit their assignments by Friday.
  • Apple: He ate five apples as a healthy snack.
  • Table: They purchased a new table for the dining room.
  • Thought: He shared his thoughts on the matter during the meeting.
  • Decision: Making important decisions requires careful consideration. 

6. Mass Nouns: Mass nouns, also known as uncountable nouns or non-count nouns, refer to substances, concepts, or entities that are treated as indivisible wholes. Unlike countable nouns, mass nouns cannot be easily counted as separate units. They are generally used to describe things that can't be quantified in discrete numbers. Mass nouns often lack a plural form or use the same form for both singular and plural.

Examples of Mass Nouns in Sentences.

  • Water: The lake was crystal clear, and the water sparkled in the sunlight.
  • Air: The mountaineers found the air thin and difficult to breathe at high altitudes.
  • Sugar: She added a spoonful of sugar to her coffee to sweeten it.
  • Furniture: Their new house was empty, so they needed to buy furniture.
  • Knowledge: Acquiring knowledge is a lifelong journey.
  • Wisdom: Older people are often respected for their wisdom.
  • Information: The internet provides a vast amount of information on various topics.
  • Money: They lost all their money in the stock market crash.

7. Collective Nouns: Collective nouns refer to groups of people, animals, or things. They are singular words that represent a collection of individuals. While the noun itself is singular, it refers to multiple entities considered as one unit. Collective nouns are often used to simplify language and avoid repetition when referring to a group.

Examples of Collective Nouns in Sentences.

  • Team: The team is practicing hard for the upcoming championship.
  • Family: The family went on a vacation to the mountains.
  • Herd: A herd of elephants was crossing the river.
  • Flock: A flock of birds flew across the sky in formation.
  • Pack: We saw a pack of wolves in the forest.
  • School: A school of fish swam gracefully in the clear water.
  • Audience: The audience applauded after the performance.
  • Crowd: A large crowd gathered to watch the parade.
  • Committee: The committee met to discuss the new policies.

8. Compound Nous: Compound nouns are formed by combining two or more words to create a new, single noun. These words can be connected by hyphens and spaces, or they can be written as one word. Compound nouns can be made up of various combinations of words, including nouns, verbs, adjectives, and prepositions. They express a single concept or idea.

Examples of Compound Nouns in Sentences.

  • Basketball: We enjoy playing basketball in the evenings.
  • Toothpaste: Make sure you use toothpaste with fluoride.
  • Raincoat: Don't forget to bring your raincoat; it might rain later.
  • Bookshelf: I need to organize the books on the bookshelf.
  • Sunglasses: Wear sunglasses to protect your eyes from the sun.
  • Moonlight: The garden looked magical in the moonlight.
  • Newspaper: I read the newspaper every morning for updates.
  • Passport: Make sure you have your passport before traveling abroad.

Noun: FAQs.

What is a Noun?

Ans: A noun is a word that represents a person, place, thing, or idea. It is a fundamental part of speech and plays a crucial role in constructing sentences.

What are the Types of Nouns in English Grammar?

Ans: There are 8 types of nouns in English grammar, including common nouns, proper nouns, concrete nouns, abstract nouns, countable nouns, uncountable nouns, collective nouns, and compound nouns.

Can you provide examples of common nouns?

Ans: Certainly! Common nouns include words like "dog," "city," "book," "table," and "idea." They refer to general, non-specific entities.

Are there rules for pluralizing nouns?

Ans: Yes, there are various rules for pluralizing nouns. Generally, you add "s" to form the plural, but irregular nouns may have different plural forms (e.g., "child" becomes "children").

What is the function of nouns in a sentence?

Ans: Nouns serve as the building blocks of sentences. They can function as subjects, or objects, or provide essential information about the people, places, things, or ideas being discussed.

Zeller's Congruence Algorithm in Python | Find Day of a Date.

Zeller's Congruence is an algorithm devised by Christian Zeller to calculate the day of the week for a given date. It's a simple algorithm that works for any date in the Gregorian calendar. The formula is as follows:
Zeller's Congruence Formula
Where:
  • h is the day of the week (0 = Saturday, 1 = Sunday, ..., 6 = Friday)
  • q is the day of the month
  • m is the month (3 = March, 4 = April, ..., 14 = February; January and February are counted as months 13 and 14 of the previous year)
  • K is the year of the century (i.e., year mod 100)
  • J is the zero-based century (actually ⌊ year/100 ⌋)

Python Program to Find the Day of a Date.

We use Zeller's Congruence Algorithm to find the day of any date in Python. Below is the code implementation to do so.

Python Code.
# Python code to find day of week for any date
def zellers_congruence(day, month, year):
    if month < 3:
        month += 12
        year -= 1

    K = year % 100
    J = year // 100

    h = (day + (13 * (month + 1)) // 5 + K + K // 4 + J // 4 - 2 * J) % 7

    # List of day names
    days_of_week = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

    # Adjust result (0 corresponds to Saturday)
    return days_of_week[(h + 5) % 7]

# Example
day = 25
month = 7
year = 2023
day_of_week = zellers_congruence(day, month, year)
print(f"The day of the week for {day}-{month}-{year} is {day_of_week}.")
Output:
The day of the week for 25-7-2023 is Sunday.

This code takes a date as input and returns the day of the week using Zeller's Congruence. The result is an integer where 0 corresponds to Saturday, 1 to Sunday, and so on. We are using a list of days to replace the output integer with matching day of the week.

Python Program to Reverse the Given Array.

Given an integer array of size n, our task is to write a Python code to print the elements of the array in reverse order. 

Example:

Input: arr = [1, 2, 3, 4, 5]
Output: Reverse order = 5, 4, 3, 2, 1

Input: arr = [10, 5, -1, 4]
Output: Reverse Order = 4, -1, 5, 10
 
Reverse Array in Python

Reverse the Given Array in Python.

We can reverse any given array by iterating through the array, swapping the first and last elements, then the second and second-to-last, and so on. We continue the swap process until we reach the middle of the array. We will need two variables initially pointing to the first and last element of the array for swapping. 

Python Code to Reverse Array Elements.
# Python code to Reverse given array
def reverse_array(arr):
    start, end = 0, len(arr) - 1
    
    # Print original array
    print("Original Array:", arr)

    while start < end:
        # Swap elements at start and end indices
        arr[start], arr[end] = arr[end], arr[start]
        start += 1
        end -= 1

    # Print reversed array
    print("Reversed Array:", arr)
    return arr

# Example Usage
original_array = [1, 2, 3, 4, 5]
reversed_array = reverse_array(original_array.copy())
Output:
Original Array: [1, 2, 3, 4, 5]
Reversed Array: [5, 4, 3, 2, 1]
  • Time Complexity: O(n)
  • Space Complexity: O(1)

Reverse an Array Using Python Slicing Method.

We can also use the Python Slicing technique to reverse an array. In this method, the slice notation [::-1] is used to reverse the array. It starts from the end and moves towards the beginning with a step of -1.

Python Code:
# Python code to reverse an array using slicing
def reverse_array(arr):
    reversed_arr = arr[::-1]
    return reversed_arr

# Example usage
original_array = [1, 2, 9, 3, 5]
reversed_array = reverse_array(original_array)

# Print the result
print("Original Array:", original_array)
print("Reversed Array:", reversed_array)
Output:
Original Array: [1, 2, 9, 3, 5]
Reversed Array: [5, 3, 9, 2, 1]
  • Time Complexity: O(n) where n is the length of the array
  • Space Complexity: O(n) because slicing creates a new array.

So these are two methods to reverse any given array in Python and my favorite is the slicing method because is just one line of code and easy to remember but it is not good in terms of space complexity.

Python Program to Find the Smallest Element in an Array.

Given an integer array of size n, the task is to write Python code to find the smallest element present in the given array. 

Example:
Input: arr = [2, 6, 1, 3]
Output: Smallest Element: 1

Input: arr = [5, 9, 3, -1, 1]
Output: Smallest Element: 0

There are multiple methods to find the smallest element of an array in Python and here in this tutorial, we will learn two simplest approaches to do so. 

Approach 1: Brute Force (Linear Search)

The linear search technique entails a systematic traversal of the entire array, comparing each element to identify the minimum value.

Algorithm Steps:
  • Begin by setting a variable to the first element.
  • Iterate through each element.
  • For each element, execute a comparison with the current minimum.
  • If a smaller element is discovered, promptly update the minimum.
  • Conclude the process by returning the final minimum.

Python Code:
# Python code to find the smallest element of array
def find_smallest(arr):
    min_element = arr[0]
    for element in arr:
        if element < min_element:
            min_element = element
    return min_element

#function call
arr = [3, 5, -1, 2]
print("Smallest Element:",find_smallest(arr))
Output:
Smallest Element: -1
  • Time Complexity: O(n) where n is the size of the array.
  • Space Complexity: O(1) as no extra space is used.

Approach 2: Using Python min() Function.

Leveraging Python's built-in min() function simplifies the process, directly identifying the minimum element of the array.

Python Code:
# Python code to get the smallest element of the array
def find_smallest(arr):
    return min(arr)

#function call
arr = [3, 5, 0, 2, 1]
print("Smallest Element:",find_smallest(arr))
Output:
Smallest Element: 0
  • Time Complexity: O(n) where n is the size of the array.
  • Space Complexity: O(1) as a constant amount of space is required.
So these are two easy methods to find the smallest element of an array using Python Programming.

DON'T MISS

Nature, Health, Fitness
© all rights reserved
made with by templateszoo