PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to convert a string into uppercase

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 uppercase 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(" Uppercase string = %s",ch);
    return 0;
}


/* Convert string into uppercase 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<<" Uppercase string = "<<ch;
    return 0;
}

OutPut

Enter a string :pLayWithCoding

Uppercase string: PLAYWITHCODING