Translate

Labels

Friday 21 December 2012

FINDING LEAP YEAR, SWAP OF TWO NUMBERS WITHOUT TEMP VARIABLE


The program which displays the string which you given as input

main()
{
char line[80];
clrscr();
printf("Enter the phrase:");
scanf("%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]",line);
scanf("%[abcdefghijklmnopqrstuvwxyz]",line);
printf("\n The phrase you had typed in was :%s",line);
getch();

o/p
Enter the phrase:hello
The phrase you had typed in was:hello 


The program to find leap year


main()
{
int month,day,year, feb_max;
clrscr();
printf("\n Enter month and year:");
scanf("%d%d",&month,&year);
if(month==2)
{
printf("\n Month is February");
feb_max=28;
if((year%4)==0)
{
printf("\n Leap year");
feb_max=29;
}
printf("\n Max days in this month:%d", feb_max);
}
getch();
}


How the pre-increment and post-increment works


main()
{
int i;
clrscr();
i=3;
printf("i=%d\n",i);
printf("i=%d\n",++i);
printf("i=%d\n",i);
printf("i=%d\n",i++);
printf("i=%d\n",i);
getch();
}
o/p
i=3
i=4
i=4
i=4
i=5


Swap of two numbers without temp variable


main()
{
int a,b;
clrscr();
a=5;
b=10;
a=a+b;
b=a-b;
a=a-b;
printf("%d\n%d\n",a,b);
getch();
}

No comments: