[C] Afisarea si numararea cuvintelor dintr-o fraza

Scrieti un program care realizeaza citirea, afisarea si numararea cuvintelor dintr-o fraza, citita de la consola:

  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. int m=200,n,i,nrcuv=1,v[m];
  6. char fraza[m];
  7. printf("Scrieti fraza: \n= ");
  8. gets(fraza);
  9. n = strlen(fraza);
  10. for(i=0;i<=n;i++)
  11. {
  12. if(fraza[i] == ‘ ‘)
  13. {
  14. nrcuv++;
  15. v[i] = 1;
  16. }
  17. }
  18. printf("Fraza contine %d cuvinte.\n",nrcuv);
  19. printf("Cuvintele sunt:\n");
  20. for(i=0;i<=n;i++)
  21. {
  22. printf("%c",fraza[i]);
  23. if(v[i] == 1)
  24. {
  25. printf("\n");
  26. }
  27. }
  28. return 0;
  29. }
#include<stdio.h>  #include<string.h>  int main()  {  int m=200,n,i,nrcuv=1,v[m];  char fraza[m];  printf("Scrieti fraza: \n= ");  gets(fraza);  n = strlen(fraza);  for(i=0;i<=n;i++)  {  if(fraza[i] == ' ')  {  nrcuv++;  v[i] = 1;  }  }  printf("Fraza contine %d cuvinte.\n",nrcuv);  printf("Cuvintele sunt:\n");  for(i=0;i<=n;i++)  {  printf("%c",fraza[i]);  if(v[i] == 1)  {  printf("\n");  }  }  return 0;  }
Nu fi egoist, distribuie...
Facebook0Google+0Twitter0StumbleUpon0Reddit0LinkedIn0tumblr

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" extra="">