Advertisement
Benlahbib_Abdessamad

Untitled

May 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.11 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #define Max 100
  6.  
  7.  
  8. void printDsc(int begin,int end)
  9. {
  10.     if(begin != end)
  11.     {
  12.         printf(" %d ",end);
  13.         return printDsc(begin,end-1);
  14.     }
  15.     else
  16.     {
  17.         printf(" %d ",begin);
  18.     }
  19.     printf("\n");
  20. }
  21.  
  22.  
  23. void printAsc(int begin,int end)
  24. {
  25.     if(begin != end)
  26.     {
  27.         printAsc(begin,end-1);
  28.         printf(" %d ",end);
  29.     }
  30.     else
  31.     {
  32.         printf(" %d ",begin);
  33.     }
  34.    
  35. }
  36.  
  37.  
  38. void printDscAsc(int begin,int end)
  39. {
  40.     if(begin != end)
  41.     {
  42.         printf(" %d ",end);
  43.         printDscAsc(begin,end-1);
  44.         printf(" %d ",end);
  45.     }
  46.     else
  47.     {
  48.         printf(" %d ",begin);
  49.     }
  50.    
  51. }
  52.  
  53.  
  54. void printAscDsc(int n,int end)
  55. {
  56.     if(n>=0)
  57.     {
  58.         printf(" %d ",end-n);
  59.         printAscDsc(n-1,end);
  60.         printf(" %d ",end-n);
  61.     }
  62. }
  63.  
  64.  
  65. /*
  66. void printNumber(int n)
  67. {
  68.     int aInt = n;
  69.     char str[15];
  70.     int length;
  71.     sprintf(str, "%d", aInt);
  72.     if((length=strlen(str)) != 1)
  73.     {
  74.         printf(" la longueur est %d ",length);
  75.         printf(" %s ",str);
  76.         printf(" %c ",str[0]);
  77.         memcpy(str, &str[1], length-1);
  78.         printf(" %s ",str);
  79.         str[length-1]='\0';
  80.         printf(" %s ",str);
  81.         aInt=atoi(str);
  82.         printf(" %d ",aInt);
  83.         //printNumber(aInt);
  84.     }
  85.     else
  86.     {
  87.         printf(" %c ",str[0]);
  88.     }
  89. }
  90. */
  91.  
  92. void printDegit(int number)
  93. {
  94.     int reste;
  95.     if(number>=10)
  96.     {
  97.         printDegit(number/10);
  98.         reste=number % 10;
  99.         printf(" %d ",reste);
  100.     }
  101.     else
  102.     {
  103.             printf(" %d ",number);
  104.     }
  105. }
  106.  
  107.  
  108. int pgcd(int a,int b)
  109. {
  110.     if(a<b)
  111.     {
  112.         return pgcd(b,a);
  113.     }
  114.     else if(a>=b && b==0)
  115.     {
  116.         return a;
  117.     }
  118.     else if(a>=b && b!=0)
  119.     {
  120.         return pgcd(b,a % b);
  121.     }
  122. }
  123.  
  124.  
  125. void expansee(char chaine[Max],int number)
  126. {
  127.     if(number>0)
  128.     {
  129.         char * string=(char*)malloc(sizeof(char)*strlen(chaine) * 3);
  130.         int i,counter=0;
  131.         for(i=0;i<strlen(chaine);i++)
  132.         {
  133.             if(chaine[i]=='a')
  134.             {
  135.                 string[counter]='b';counter++;  string[counter]='c';  counter++;
  136.             }
  137.             else if(chaine[i]=='b')
  138.             {
  139.                 string[counter]='c';counter++;  string[counter]='a';  counter++;
  140.             }
  141.             else if(chaine[i]=='c')
  142.             {
  143.                 string[counter]='a';counter++;
  144.             }
  145.             else
  146.             {
  147.                 break;
  148.             }
  149.         }
  150.         string[counter]='\0';
  151.         printf("le resultat est : %s \n",string);
  152.         return expansee(string,number-1);
  153.     }
  154. }
  155.  
  156.  
  157.  
  158. void ex01_1()
  159. {
  160.     printf("\nFirst question Exercise 1 : \n");
  161.     printDsc(0,15);
  162. }
  163.  
  164. void ex01_2()
  165. {
  166.     printf("\nSecond question Exercise 1 : \n");
  167.     printAsc(0,15);
  168.     printf("\n");
  169. }
  170.  
  171. void ex01_3()
  172. {
  173.     printf("\nThird question Exercise 1 : \n");
  174.     printDscAsc(0,15);
  175.     printf("\n");
  176. }
  177.  
  178. void ex01_4()
  179. {
  180.     printf("\nFourth question Exercise 1 : \n");
  181.     //printAscDsc(0,15);
  182.     printAscDsc(15,15);
  183.     printf("\n");
  184. }
  185.  
  186. void ex01_5()
  187. {
  188.     printf("\nFifth question Exercise 1 : \n");
  189.     printDegit(10005);
  190.     printf("\n");
  191. }
  192.  
  193. void ex02()
  194. {
  195.     printf("\nExercise 2 : \n");
  196.     printf("le pgcd de 35 et 15 est : %d \n",pgcd(35,15));
  197. }
  198.  
  199. void ex03()
  200. {
  201.     printf("\nExercise 3 : \n");
  202.     printf("Input is  : abc \n");
  203.     expansee("abc",4);
  204. }
  205.  
  206.  
  207.  
  208. int main()
  209. {
  210.     printf("Programmé par Benlahbib Abdessamad & Majana Yassine Master SIRM \n\n");
  211.     ex01_1();
  212.     ex01_2();
  213.     ex01_3();
  214.     ex01_4();
  215.     ex01_5();
  216.     ex02();
  217.     ex03();
  218.     getchar();
  219.     return 1;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement