Advertisement
Guest User

tableaux

a guest
Feb 14th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define DIM 1000
  5.  
  6. int clear_input_buffer(void)
  7. {
  8. int ch;
  9. while(((ch = getchar()) != EOF) && (ch != '\n')) /* void */
  10. ;
  11. return ch;
  12. }
  13.  
  14. int main(int argc, char** argv)
  15. {
  16.  
  17. int reponse;
  18.  
  19. do {
  20. printf("choose: \n 1: td 3 n 4 \n 2: td 3 n 6 \n 3: td 3 n 7 \n");
  21. scanf("%d", &reponse);
  22. } while(reponse != 1 && reponse != 2 && reponse != 3);
  23.  
  24. if(reponse == 1) {
  25.  
  26. int i, j;
  27. char phrase[DIM], phrase1[DIM];
  28.  
  29. printf("entrez une phrase\n");
  30. scanf("%s", phrase);
  31. int len = strlen(phrase);
  32. for(i = 0; i < len; i++) {
  33. phrase1[i] = phrase[i];
  34. }
  35.  
  36. printf("combien de permutations de positions voulez vous faire ? maximum : %d \n", len);
  37.  
  38. do {
  39. scanf("%d", &reponse);
  40. } while(reponse < 0 || reponse >= len);
  41.  
  42. for(i = 0, j = 1; i < reponse; i++, j++) {
  43. /*
  44. //avec un tableau secondaire
  45. phrase[i] = phrase1[j];
  46. phrase[j] = phrase1[0];
  47. */
  48.  
  49. // sans un tableau secondaire
  50. phrase[i] = phrase[j];
  51. phrase[j] = phrase[0];
  52.  
  53. printf("%s \n", phrase);
  54. }
  55.  
  56. printf("le resultat final: %s", phrase);
  57. }
  58.  
  59. if(reponse == 2) {
  60.  
  61. clear_input_buffer();
  62. char phrase[DIM];
  63. int i, j;
  64.  
  65. printf("entrez une phrase:\n");
  66.  
  67. gets(phrase);
  68. int len = strlen(phrase);
  69.  
  70. for(i = len; i >= -1; i--) {
  71. if(phrase[i] == 32 || i == -1) {
  72. for(j = i + 1; j < len; j++) {
  73. printf("%c", phrase[j]);
  74. if(phrase[j] == 32)
  75. break;
  76. }
  77. printf(" ");
  78. }
  79. }
  80. }
  81.  
  82. if(reponse == 3) {
  83.  
  84. clear_input_buffer();
  85. char phrase[DIM];
  86. int i, j, nbDeMots = 1;
  87.  
  88. printf("entrez une phrase:\n");
  89. gets(phrase);
  90. int len = strlen(phrase);
  91.  
  92. for(i = 0; i < len; i++) {
  93. if(phrase[i] == 32) {
  94. nbDeMots++;
  95. }
  96. }
  97. printf("\nIl y a %d mots.", nbDeMots);
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement