Tuesday, July 19, 2011

Program to convert all lowere case char to upper & vice versa also print all in upper & in lower

/*Serial No.156     [swami137.cpp]*/

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[20];
clrscr();
printf("\nEnter first string= ");
scanf("%[^\n]",str1);
/**to convert upper to lower case & vice versa**/
for(int i=0;str1[i]!='\0';i++)
    {
    if(str1[i]>=97&&str1[i]<123)
        str1[i]=str1[i]-32;
    else if(str1[i]>=65&&str1[i]<91)
        str1[i]=str1[i]+32;
    }
printf("\n\nString after convering upper to lower & vice versa=\n\t%s",str1);

/**for upper case**/
for(i=0;str1[i]!='\0';i++)
    {
    if(str1[i]>=97&&str1[i]<123)
        str1[i]=str1[i]-32;
    }
printf("\n\nString in Upper case=\n\t%s",str1);

/**for lower case**/
for(i=0;str1[i]!='\0';i++)
    {
    if(str1[i]>=65&&str1[i]<91)
        str1[i]=str1[i]+32;
    }
printf("\n\nString in Lower case=\n\t%s",str1);
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...