Jump to content
Rickets_temp

[C++] Extragerea consoanelor dintr-un sir

Recommended Posts

Detaliaza te rog.

In ce sens extragerea?

Afisarea doar consoanelor din sir?

Notarea consoanelor existente in sir?

E simplu, pentru stocarea consoanelor intr-un alt string faci asa:

Intr-un string pui consoanele. In alt string pui sirul tau.

Un al 3-lea sir va stoca consoanele.

Pentru fiecare caracter din sir, treci prin string-ul cu consoanele. Cand ai gasit o consoana, o introduci in al 3-lea string, si mergi la urmatorul caracter din sir.

Link to comment
Share on other sites

  • Active Members

#include<iostream.h>
int main(void)
{
char s[50];
int voc=0, cons=0,i;
cout<<"Dati sirul de caractere "; cin.getline(s,50);
i=0;
while(s[i]!=0)
{
switch (s[i]){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': {voc++;break;}
default : cons++;
}
i++;
}
cout<<"Numarul de consoane ale sirului este
"<<cons<<endl;
}

Asta e numarul de consoane. Adaptezi in functie de ce vrei

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...