(C++) CPP Programs - 22

Friday, December 14, 2007

22. Write a C program to read a sentence and replace lower case characters by uppercase and vice-versa. Output the given sentence as well as the case converted sentence on two different lines.



/*Upper case to Lower case and vice-versa*/



#include

#include

#include



void main()

{

char str[45];

int i,n,j;



clrscr();



printf("\nEnter a string\n");

gets(str);



printf("\nThe given string is\n");

puts(str);



n=strlen(str);



for(i=0;i < n;i++)

{

if(isupper(str[i]))

str[i]=tolower(str[i]);

else if(islower(str[i]))

str[i]=toupper(str[i]);

}

printf("\nThe new string is\n");

puts(str);



getch();

}

0 comments:

Post a Comment

Chitika

About This Blog

Followers

Blog Archive

  © Blogger template The Professional Template II by Ourblogtemplates.com 2009

Back to TOP