Saturday, 11 April 2015

Display the day of Gregorian calendar.

According to the Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard. Write a program to find out what is the day on 1st January of this year.


Code

void main(){
char* vDay[] ={"Friday","Saturdy","Sunday","Monday","Tuesday","Wednesday","Thursday"};
int vYear;
clrscr();

printf("Enter a Year Format YYYY: ");
scanf("%d",&vYear);
printf("%s On 01.01.%d",vDay[vYear%7],vYear);

getch();
}



Output




Leap Year or Not!

Any year is input through the keyboard. Write a program to determine where the year is leap year or not. (Hint: Use the % (modulus) operator)


Code

void main(){
int var1,vLyear;
clrscr();
printf("Enter a year: ");
scanf("%d",&var1);
vLyear = var1%4;
if(vLyear==0)
printf("Its Leap Year!   %d",var1);
else
printf("Its not Leap Year!   %d",var1);
getch();
}



Output






Add 1 to each five digit numbers

If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example if the number that is input is 12391 then the output should be displayed as 23402.



Code

void main(){
long int var1,i,vSize=0,rVar=0,vL,vAd=0;  // Variable declaration 
clrscr();
printf("Enter an Integer: ");    /// Getting the input from the user
scanf("%ld",&var1);

vL=var1;                          /// Counding the input digits
while(vL>0){
vSize++;
vL /=10;
}
vL = var1;
printf("\n Size of Integer is %ld",vSize);

///          Reversing the input digits
for(i=1;i<=vSize;i++){
rVar *= 10;
rVar += vL%10;
vL /=10;
}

printf("\n Reverse Integer is %ld",rVar);

/// Making in original form by adding 1 (One) to each digit
for(i=1;i<=vSize;i++){
vAd *= 10;
vAd += (((rVar%10)+1)%10);
rVar /=10;
}

printf("\n After adding 1 to each Integer is %ld",vAd);
getch();
}


Output of the code