PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on If & Else

Program to replace vowel with star (*)

Input - Output

Input
Enter a string: Playwithcoding

Output
After replacing Vowel : pl*yw*thc*d*ng

Algorithm

Step 1: START

Step 2: Enter a string as an input.

Step 3: Check each character of the string:

    if ch[i]=A,E,I,O,U or a,e,i,o,u

       print "*";

    else

       print str[i];

Step 4: END

CODE


/* Replace vowel from string */
#include <stdio.h>
#include <string.h>
int main()
{
      char str[30];
      printf(" Enter a string: ");
      gets(str);
      printf("After replacing vowel from string : ");
      for(int i=0;str[i];i++)
     {
          if(str[i]=='A'||str[i]=='a'||str[i]=='E'||str[i]=='e'||str[i]=='I'||str[i]=='i'||str[i]=='O'||str[i]=='o'||str[i]=='U'||str[i]=='u')
                printf("*");
          else
            printf("%c",str[i]);
     }
    return 0;
}


/* Replace vowel from string */
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
      char str[30];
      cout<<" Enter a string: ";
      gets(str);
      cout<<"After replacing vowel from string : ";
      for(int i=0;str[i];i++)
     {
          if(str[i]=='A'||str[i]=='a'||str[i]=='E'||str[i]=='e'||str[i]=='I'||str[i]=='i'||str[i]=='O'||str[i]=='o'||str[i]=='U'||str[i]=='u')
                cout<<"*";
          else
            cout<<str[i];
     }
    return 0;
}

OutPut

Enter a string: Playwithcoding

After replacing Vowel : pl*yw*thc*d*ng