PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to convert a string into lowercase

Input - Output

Input
Enter a string : PlayWithCoding

Output
Uppercase string: playwithcoding

Algorithm

Step 1: START

Step 2: Enter a string as an input.

Step 3: Check each character of the string:

    if(ch[i]>='A' && ch[i]<='Z')

       ch[i]=ch[i]+32;

   print resulatant string

Step 4: END

CODE


/* Convert string into lowercase alphabet */

#include  <stdio.h>
int main()
{
      char ch[30];
      printf(" Enter a string : ");
      scanf("%s",ch);
      for(int i=0;ch[i];i++)
          if(ch[i]>='A' && ch[i]<='Z')
              ch[i]=ch[i]+32;
       printf(" Lowercase string = %s ",ch);
    return 0;
}


/* Convert string into lowercase alphabet */
#include <iostream>
using namespace std;
int main()
{
      char ch[30];
      cout<<" Enter a string : ";
      cin>>ch;
      for(int i=0;ch[i];i++)
          if(ch[i]>='A' && ch[i]<='Z')
              ch[i]=ch[i]+32;
       cout<<" Lowercase string = "<<ch;
    return 0;
}

OutPut

Enter a string : PlayWithCoding

Uppercase string: playwithcoding