Giter Club home page Giter Club logo

date-program-in-c's Introduction

Date-Program-in-C

#include <stdio.h>
#include <string.h>

struct Date {
	int day, month, year;  //these variables uses for getting input from user
};

int main(){
	struct Date d;
	
	//first s uses here for calculating Year days upto speicfied date then secondaly uses for storing weak days number
	int s= 0;       
	//these variable uses for setting month and weakday
	char month[15];
	char weakDay[15];
	
	printf("Enter Date : ");
	scanf("%d", &d.day);
	printf("Enter Month: ");
	scanf("%d",&d.month);
	printf("Enter Year: ");
	scanf("%d",&d.year);
	
	//Code for finding current day of specified date
	
	//for setting month value
	int mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
	//uses for checking leap year or not
	if((d.year % 4 == 0) || ((d.year % 4 == 0) && (d.year % 100 != 0))) {
		mon[1] = 29;
	}
	
	for (int i =0; i < d.month-1; i++){
		s = s + mon[i]; //uses for calculating days in year upto specified date
	}
	//This formula uses for getting weak day number
	s = s + (d.day + d.year + (d.year / 4) -2);
	s = s%7;
	
	//uses for getting desired day
	
	switch(s){
	case 0: 
		strcpy(weakDay, "sunday");
		break; 
	case 1: 
		strcpy(weakDay, "monday");
		break;
	case 2: 
		strcpy(weakDay, "tuesday");
		break;
	case 3: 
		strcpy(weakDay, "wednesday");
		break;
	case 4: 
		strcpy(weakDay, "thursday");
		break;
	case 5: 
		strcpy(weakDay, "friday");
		break;
	case 6: 
		strcpy(weakDay, "saturday");
		break;
	default: 
		printf("Not valid");
	}
	
	
	//Uses for getting desired month
	switch(d.month)
	{
	case 0: 
		strcpy(month, "January");
		break; 
	case 1: 
		strcpy(month, "february");
		break;
	case 2: 
		strcpy(month, "march");
		break;
	case 3: 
		strcpy(month, "april");
		break;
	case 4: 
		strcpy(month, "may");
		break;
	case 5: 
		strcpy(month, "june");
		break;
	case 6: 
		strcpy(month, "july");
		break;
	case 7: 
		strcpy(month, "august");
		break;
	case 8: 
		strcpy(month, "september");
		break;
	case 9: 
		strcpy(month, "october");
		break;
	case 10: 
		strcpy(month, "november");
		break;
	case 11: 
		strcpy(month, "december");
		break;		
	default: 
		strcpy(month, "Not valid");
	}
	//desired output form 
	printf("Day => %s , %d : %s , %d : %d", weakDay, d.month, month,d.year, d.year % 100);
	
	return 0;	
}

date-program-in-c's People

Contributors

ahmadjajja avatar

Stargazers

mohsin raza abid avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.