Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008

By | April 17, 2016

Write a program in ‘C’ to check whether the given year is leap or not. Also explain the logic of the program. 8m Dec2008

The leap year formula is:

A leap year is divisable by 4, but not by 100 (except if divisable by 400.)

 

#include<stdio.h>
void main(){
int year;
clrscr();
printf(“Enter any year: “);
scanf(“%d”,&year);

if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf(“%d is a leap year”,year);
else
printf(“%d is not a leap year”,year);

getch();
}

Code:-

 

cc#include<stdio.h>
void main(){
int year;
clrscr();
printf("Enter any year: ");
scanf("%d",&year);
 
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
 
getch();
}

 

ScreenShot:-

C_program_Leap_Year

C_program_Leap_Year_Output

 

 

 

(c) Write a function definition to find the smallest among the given three numbers. 5

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-macro-to-find-the-smallest-number-among-3-given-numbers-7m-jun2007

 

4. (a) Without using the’strcpy’function, write a program to copy contents of string 2 to string 1, and find the length of the copied string using pointers. 10

Solved program can be found on this link http://cssimplified.com/c-programming/write-a-program-that-does-not-use-the-inbuilt-string-functions-to-perform-the-following-10m-jun2006

 

5. (a) Design an algorithm and draw corresponding flow chart to convert a decimal number to its Hexadecimal equivalent. 10

Solved program can be found on this link http://cssimplified.com/c-programming/design-an-algorithm-and-draw-corresponding-flowchart-to-convert-a-decimal-number-to-its-hexadecimal-equivalent-10m-dec2005

 

(b) Explain the following storage class specifiers of a variable in terms of default value, lifetime, scope purpose and limitations (with an example) 10

Solved program can be found on this link http://cssimplified.com/c-programming/explain-various-types-of-storage-classes-in-c-with-example-for-each