| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
|||||||
| C C Interview Questions asked in various Interviews. Professionals are invited to share Answers for these C Interview Questions. C Interview Questions with answers, Experiences, Career Advices, Tips and more. |
![]() |
|
|
LinkBack | Thread Tools | Rate Thread | Display Modes |
|
|
#2 (permalink) |
|
Junior Member
Join Date: Oct 2008
Age: 24
Posts: 14
Thanks: 2 Thanked 0 Times in 0 Posts Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: Does C have any Year 2000 problems
Dear Sivani, No, The actual rules for the present Gregorian calendar are that leap years occur every four years, but not every 100 years, except that they do occur every 400 years, after all. In C, these rules can be expressed as: year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) Actually, if the domain of interest is limited (perhaps by the range of a time_t) such that the only century year it encompasses is 2000, the expression (year % 4 == 0) /* 1901-2099 only */ is accurate, if less than robust. If you trust the implementor of the C library, you can use mktime to determine whether a given year is a leap year; Note also that the transition from the Julian to the Gregorian calendar involved deleting several days to make up for accumulated errors. (The transition was first made in Catholic countries under Pope Gregory XIII in October, 1582, and involved deleting 10 days. In the British Empire, eleven days were deleted when the Gregorian calendar was adopted in September 1752. A few countries didn't switch until the 20th century.) Calendar code which has to work for historical dates must therefore be especially careful. eg: Write a program to find whether an year is leap or not? int leap(int year){ if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) return 1; else return 0; } int main(){ int year; printf("Enter Year ?\n"); scanf("%d",&year); if(leap(year)) printf("Leap Year \n"); else printf("Non Leap \n"); } output: Enter Year ? 2000 Leap Year Enter Year ? 2001 Non Leap |
|
|
|
![]() |
| Tags |
| c language , interview questions |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Get Inspired With The 17 Year Old CEO... | vjsreevs | Inspire yourself & Others - Leaders Zone | 3 | 10-12-08 11:52 PM |
| specialty of this NEW year | AjayKumar.Kataram | FRIENDSHIP & LOVE | 1 | 02-01-07 11:34 AM |
| some recent major computer system failures caused by software bugs | AjayKumar.Kataram | Latest Tech News & Innovations | 2 | 21-12-06 05:06 PM |
| What are 5 common problems in the software development process? | das.testing | Testing Tools & QA | 0 | 10-11-06 10:56 PM |
| System Administrator Experience 0 year- 1 year | sridhar | FRESHER JOBS | 3 | 05-09-06 09:33 PM |