Q:

C program to change the case from upper to lower and lower to upper

0

C program to change the case from upper to lower and lower to upper

The following program changes the case of alphabets. If a lower/upper case alphabet is present, we convert it to upper/lower case.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>

int main ()
{
   int c = 0;
   char ch, s[1000];

   printf("Input a string\n");
   gets(s);
   
   while (s[c] != '\0') {
      ch = s[c];
      if (ch >= 'A' && ch <= 'Z')
         s[c] = s[c] + 32;
      else if (ch >= 'a' && ch <= 'z')
         s[c] = s[c] - 32;  
      c++;  
   }
   
   printf("%s\n", s);

   return 0;
}

An output of the program:

Input a string
abcdefghijklmnopqrstuvwxyz{0123456789}ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ{0123456789}abcdefghijklmnopqrstuvwxyz

If a digit or special character is present in a string, it's left as it is.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now