Post Page Advertisement [Top]

C-Programming

How to write a program in c to convert upper case to lower case and vice versa of a string ?

convert upper case to lower case and vice versa of a string.

Steps of programming :-
  1. First we Initialize a variable as int and another as string (e.g char s[100] int i)
  2. then we get input of a string in s.
  3. then we start a loop from i =0 to i=100 here i is position of char in string.this loop will give one by one all character of string and we will change that.
  4. as we know that ASCII value of, A-Z is b/w 65-90, and a-z is b/w 97-122. he we can see 65+32=97 means A+32=a,B+32=b an so on.
  5. so we use s[i]=s[i]-32 for convert for convert to convert small latter to capital latter and s[i]=s[i]+32 for convert for convert to convert capital latter to small latter 
  6. then our program will complete.

CODE:-

#include<stdio.h>
#include<string.h>
void main()
{int i;
char s[100];
clrscr();
printf("\nType Here : ");
gets(s);
for(i=0;i!=100;i++)
{
if(s[i]>=97 && s[i]<=122)
s[i]=s[i]-32;
else if(s[i]>=65 && s[i]<=90)
s[i]=s[i]+32;
}
printf("\nString after changing case =%s",s);
getch();
}

convert upper case to lower case and vice versa of a string.
OUTPUT
Dizit Operators
Thank-you

No comments:

Post a Comment

Bottom Ad [Post Page]