Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define DIM 1000
- int clear_input_buffer(void)
- {
- int ch;
- while(((ch = getchar()) != EOF) && (ch != '\n')) /* void */
- ;
- return ch;
- }
- int main(int argc, char** argv)
- {
- int reponse;
- do {
- printf("choose: \n 1: td 3 n 4 \n 2: td 3 n 6 \n 3: td 3 n 7 \n");
- scanf("%d", &reponse);
- } while(reponse != 1 && reponse != 2 && reponse != 3);
- if(reponse == 1) {
- int i, j;
- char phrase[DIM], phrase1[DIM];
- printf("entrez une phrase\n");
- scanf("%s", phrase);
- int len = strlen(phrase);
- for(i = 0; i < len; i++) {
- phrase1[i] = phrase[i];
- }
- printf("combien de permutations de positions voulez vous faire ? maximum : %d \n", len);
- do {
- scanf("%d", &reponse);
- } while(reponse < 0 || reponse >= len);
- for(i = 0, j = 1; i < reponse; i++, j++) {
- /*
- //avec un tableau secondaire
- phrase[i] = phrase1[j];
- phrase[j] = phrase1[0];
- */
- // sans un tableau secondaire
- phrase[i] = phrase[j];
- phrase[j] = phrase[0];
- printf("%s \n", phrase);
- }
- printf("le resultat final: %s", phrase);
- }
- if(reponse == 2) {
- clear_input_buffer();
- char phrase[DIM];
- int i, j;
- printf("entrez une phrase:\n");
- gets(phrase);
- int len = strlen(phrase);
- for(i = len; i >= -1; i--) {
- if(phrase[i] == 32 || i == -1) {
- for(j = i + 1; j < len; j++) {
- printf("%c", phrase[j]);
- if(phrase[j] == 32)
- break;
- }
- printf(" ");
- }
- }
- }
- if(reponse == 3) {
- clear_input_buffer();
- char phrase[DIM];
- int i, j, nbDeMots = 1;
- printf("entrez une phrase:\n");
- gets(phrase);
- int len = strlen(phrase);
- for(i = 0; i < len; i++) {
- if(phrase[i] == 32) {
- nbDeMots++;
- }
- }
- printf("\nIl y a %d mots.", nbDeMots);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement