×

Find Day from Day in C Without using function

Introduction: In the given article, I find daily in C without using functions. It takes 365 days for the earth to revolve around the sun. It will be close to 365.25 days. So if 12 months appear as his year, four years will end in a total of 1 day. This happens once every four years. Four-digit years such as 0004 and 0008 are leap years starting at 0001. A year has 12 months. They have the subsequent lengths (quantity of Days): February 28 (if it is a nonleap year 12 months) and February 29 (if it is a nonleap year 12 months).

 March contains 31 days thru April contains 30 days, May also contains 31 days, June contains 30 days, August contains 31 days, September contains 30 days, December contains 31 days via January contains 31 days. The full is 365 days if the year is a nonleap year and 366 days if the year is a leap year. We observed a reality that is 01-01-0001 with the aid of moving backward. That is Monday, January 1, 0001. This is the foundation of your program.

Example 1: Here is an example of the tag by tag in C without using functions. So, below we write a program about it –

#include <stdio.h>
int dayofweek (int d, int m, int y)
{	
Static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= m < 3;
return (y + y/4 – y/100 + y/400 + t[m-1] + d) % 7;
}
int main()
{
int day = dayofweek( 05, 05, 2000);
printf (“%d”, day);
return 0;
}

Output: We compile the above program and run it. Then the result is:

5 (Friday)

Example 2: Here, we give another example of finding day from the day in C without using function. So, below we write a program about it –

# include < stdio . h >   
# include < conio . h >   
void main ( )   
{   
int date , month , year , i , r , s = 0 ;   
 int month [ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;    
char week [ 7 ] [ 10 ] ;   
 clrscr ( ) ;   
 strcpy ( week [ 0 ] , " Sunday " ) ;   
 strcpy ( week [ 1 ] , " Monday " ) ;   
strcpy ( week [ 2 ] , " Tuesday " ) ;   
 strcpy ( week [ 3 ] , " Wednesday " ) ;   
 strcpy ( week [ 4 ] , " Thursday " ) ;   
 strcpy ( week [ 5 ] , " Friday " ) ;   
 strcpy ( week [ 6 ] , " Saturday " ) ;   
 printf ( "Please enter a valid date ( dd / mm / yyyy ) : " ) ;   
 scanf ( " % d / % d / % d " , & date , & month , & year ) ;   
 if ( ( year % 400 = = 0 ) | | ( ( year % 4 = = 0 ) & & ( year % 100 ! = 0 ) ) )   
  month [ 1 ] = 29 ;   
 for ( i = 0 ; i < month - 1 ; i + + )   
 s = s + month [ i ] ;   
 s = s + ( date + year + ( year / 4 ) - 2 ) ;   
 s = s % 7 ;   
 printf ( " \ n The day is : % s " , week [ s ] ) ;   
return 0;   
}  

Output: We compile the above program and run it. Then the result is:

Please enter a valid date ( dd / mm / yyyy ) : (05/04/2000)
The day is: Monday

Explain the above program: The array month[12] of integer type can store 12 different integers. Also, this array is initialized at the time of declaration. For example, the first value of 30 indicates that June has 30 days. Char [7] [10] - This is a one-kind array from the month [12] array cited earlier than when you consider that it's far a multidimensional array of the kind individual. Integers are used to record the day, month, and 12 months the person provided. Other integers are I, r, and s. Here, instead of initializing the char[7][10] array on assertion, instead of initializing the month[12] array, we use the C language string replication property strcpy.end.

So here, we search by day in C without using a function. It also shows an example and the output of this program.


Related Topics

File Operations in C

Why do I need the file? All data will be lost when the program exits. Saving data to a file keeps it safe even if the program stops working. If there...

6 minutes read.

How to create a binary file in C?

Creating a binary file in C language is very simple, requiring only some specific functions to be implemented. There are also other binary modes: read, and write, which will be...

7 minutes read.

Variable Declaration in C

What is a Variable? A Variable is nothing more than a name for a memory place where data/information can be stored. Any alphabet (from a to z or A to Z), the...

4 minutes read.

C Token

C Token and Keyword The C tokens are the basic buildings blocks in C language which are constructed together to write a C program. Each and every smallest individual unit in the C program is...

2 minutes read.

Multiplication table program in C using For loop

Before we move on the program of multiplication table of any natural number, first we have to know about the For loop statement. The syntax of ‘for’ loop in C programming...

3 minutes read.

Memory layout in C

Memory layout in C The C language is designed so that it becomes easier for a programmer to decide the amount of memory they want to use in a program. C program...

4 minutes read.

Calendar application in C

Introduction to the calendar application We all are familiar with the calendar. It plays a crucial role in our daily life. We run toward the calendar whenever we want to know...

6 minutes read.

Fibonacci series in C

We have learned about the Fibonacci series in mathematics. For a quick recap, A Fibonacci series is the sequence of numbers following a certain pattern i.e., the next number should...

3 minutes read.

How to Find Square Free Numbers in C?

Introduction Square-free number program is a typical interview and academic question in C Programming. In this section, we will define square-free integers, construct algorithms and C program to print the nth...

11 minutes read.

GCD program of two numbers in C

GCD stands for Greatest Common Divisor, which is also known as Highest Common Factor, which can be abbreviated as HCF. Mathematically it can be defined as any two positive integers...

3 minutes read.

File Handling in C

File Handling is used to open, read, write, search and close file.  C files I/O functions handles data on secondary storage device. File handling function: There are varioushandling functions in C. Function Operation fopen() It is...

4 minutes read.

Format Specifier in C

Format Specifier in C Format specifiers can be described as an operator that is used to print the data referred by any object or variable in combination with the printf ()...

3 minutes read.

Typecast vs. typedef in C

Typecast vs. typedef in C Typecast In the C programming language, converting the data type from one form to another is known as type casting or the type conversion. It is a...

5 minutes read.

Segmentation Fault in C

Segmentation Fault in C In the C programming language, segmentation fault or segmentation violation or core dump is a condition that the hardware component raises to protect the memory by indicating...

4 minutes read.

C Language Environment Setup

To compile C program, we must have GCC compiler installed on our machine. In this C tutorial, all the examples are compiled and tested using GCC compiler. Although we can...

3 minutes read.

Builtin functions of GCC compiler

Certain built-in functions are present in the GCC compiler. These features are as follows: Function_ built in_popcount (x) The number of 1s in data of the integer type can be counted using...

3 minutes read.

Variables in C

A variable can be defined as a name allocated to a storage space that can be manipulated by our programs. Every variable in C arbitrates about the overall layout and...

5 minutes read.

Program to Find Mode of an Array in C

Mode is the highest occurring value or number in a given set of data elements. In a group of data values, a value that occurs most frequently is considered to...

3 minutes read.

What is String Comparison in C

String comparison is the process of comparing two strings (sequences of characters) to determine if they are equal, or if one is greater or less than the other. The comparison...

4 minutes read.

Git Hooks

Git Hooks Overview Just like other version control systems, Git has its way to deliver customized scripts whenever some important activity occurs. The hooks act just like the triggers or catalysts...

4 minutes read.