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".

DON'T MISS

Tech News
© all rights reserved
made with by AlgoLesson