Translate

Labels

Showing posts with label CONDITIONAL PROGRAMS. Show all posts
Showing posts with label CONDITIONAL PROGRAMS. Show all posts

Friday, 21 December 2012

FINDING THE CASE OF THE GIVEN INPUT


 main()
{
int input_char;
printf("\n Enter character:");
input_char=getchar();
if(input_char==EOF)
{
printf("End of file encountered \n");
}
else if(input_char>='a'&& input_char<='z')
{
printf("Lowercase character\n");
}
else if(input_char>='A'&& input_char<='Z')
{
printf("uppercase character \n");
}
else if(input_char>=0 && input_char<=9)
{
printf("Digit \n");
}
}

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();
}

CHANGING UPPERCASE CHARACTER TO LOWERCASE CHARACTER

program displays a character entered in the uppercase in the lowercase
main()
{
int c;
printf("Enter an uppercase letter:");
c=getchar();
printf("Lowercase=");
putchar(c+32);
}

HOW TO DENOTE END OF FILE

How CTRL+Z can be used to denote end of file:
main()

{
int c;
print("Enter the character (CTRL+Z to end):");
c=getchar();
if(c!=EOF)
printf("End of file not encountered ");

o/p:
Enter the character (CTRL+Z to end):d
End of file not encountered.