Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #define Max 100
- void printDsc(int begin,int end)
- {
- if(begin != end)
- {
- printf(" %d ",end);
- return printDsc(begin,end-1);
- }
- else
- {
- printf(" %d ",begin);
- }
- printf("\n");
- }
- void printAsc(int begin,int end)
- {
- if(begin != end)
- {
- printAsc(begin,end-1);
- printf(" %d ",end);
- }
- else
- {
- printf(" %d ",begin);
- }
- }
- void printDscAsc(int begin,int end)
- {
- if(begin != end)
- {
- printf(" %d ",end);
- printDscAsc(begin,end-1);
- printf(" %d ",end);
- }
- else
- {
- printf(" %d ",begin);
- }
- }
- void printAscDsc(int n,int end)
- {
- if(n>=0)
- {
- printf(" %d ",end-n);
- printAscDsc(n-1,end);
- printf(" %d ",end-n);
- }
- }
- /*
- void printNumber(int n)
- {
- int aInt = n;
- char str[15];
- int length;
- sprintf(str, "%d", aInt);
- if((length=strlen(str)) != 1)
- {
- printf(" la longueur est %d ",length);
- printf(" %s ",str);
- printf(" %c ",str[0]);
- memcpy(str, &str[1], length-1);
- printf(" %s ",str);
- str[length-1]='\0';
- printf(" %s ",str);
- aInt=atoi(str);
- printf(" %d ",aInt);
- //printNumber(aInt);
- }
- else
- {
- printf(" %c ",str[0]);
- }
- }
- */
- void printDegit(int number)
- {
- int reste;
- if(number>=10)
- {
- printDegit(number/10);
- reste=number % 10;
- printf(" %d ",reste);
- }
- else
- {
- printf(" %d ",number);
- }
- }
- int pgcd(int a,int b)
- {
- if(a<b)
- {
- return pgcd(b,a);
- }
- else if(a>=b && b==0)
- {
- return a;
- }
- else if(a>=b && b!=0)
- {
- return pgcd(b,a % b);
- }
- }
- void expansee(char chaine[Max],int number)
- {
- if(number>0)
- {
- char * string=(char*)malloc(sizeof(char)*strlen(chaine) * 3);
- int i,counter=0;
- for(i=0;i<strlen(chaine);i++)
- {
- if(chaine[i]=='a')
- {
- string[counter]='b';counter++; string[counter]='c'; counter++;
- }
- else if(chaine[i]=='b')
- {
- string[counter]='c';counter++; string[counter]='a'; counter++;
- }
- else if(chaine[i]=='c')
- {
- string[counter]='a';counter++;
- }
- else
- {
- break;
- }
- }
- string[counter]='\0';
- printf("le resultat est : %s \n",string);
- return expansee(string,number-1);
- }
- }
- void ex01_1()
- {
- printf("\nFirst question Exercise 1 : \n");
- printDsc(0,15);
- }
- void ex01_2()
- {
- printf("\nSecond question Exercise 1 : \n");
- printAsc(0,15);
- printf("\n");
- }
- void ex01_3()
- {
- printf("\nThird question Exercise 1 : \n");
- printDscAsc(0,15);
- printf("\n");
- }
- void ex01_4()
- {
- printf("\nFourth question Exercise 1 : \n");
- //printAscDsc(0,15);
- printAscDsc(15,15);
- printf("\n");
- }
- void ex01_5()
- {
- printf("\nFifth question Exercise 1 : \n");
- printDegit(10005);
- printf("\n");
- }
- void ex02()
- {
- printf("\nExercise 2 : \n");
- printf("le pgcd de 35 et 15 est : %d \n",pgcd(35,15));
- }
- void ex03()
- {
- printf("\nExercise 3 : \n");
- printf("Input is : abc \n");
- expansee("abc",4);
- }
- int main()
- {
- printf("Programmé par Benlahbib Abdessamad & Majana Yassine Master SIRM \n\n");
- ex01_1();
- ex01_2();
- ex01_3();
- ex01_4();
- ex01_5();
- ex02();
- ex03();
- getchar();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement