Faculté des Sciences SMI3/LP2I if(A[iA]<B[iB]) Département d’Informatique {AB[iAB]=A[iA]; iAB++; iA++;} else Proposition de correction de l’examen de Programmation I (SN) {AB[iAB]=B[iB]; iAB++; iB++;} /* Si iA ou iB sont arrivés à la fin de leur tableau, alors copier le reste de l'autre Exercice 1 (4 pts) tableau*/ #include<stdio.h> while (iA<N) main (){ {AB[iAB]=A[iA]; iAB++; iA++;} int i, n, compt=0 ; while (iB<M) printf("Donner un entier "); {AB[iAB]=B[iB]; iAB++; iB++;} scanf("%d", &n); return AB; } for (i=1; i <=n/2; i++) if (n%i==0) compt+=i; Exercice 4 (4 pts) if(compt==n) printf("%d est un nombre parfait ",n); else printf("%d n'est pas un nombre parfait ",n); #include <stdio.h> } #include <string.h> main() Exercice 2 (4 pts) {char s[21],*p, *q; #include<stdio.h> int i,N; main (){ printf("Entrez une chaine (max.20 caractères) :\n"); int nbr, n, chiffre, occu=0, rest ; gets(s); printf("Entrer un nombre positif :\n"); N = strlen(s); scanf("%d", &nbr); for (p=s, q=s+(N-1); *p == *q, p<=q; p++,q--); do{ printf("Entrer un chiffre (0<= chiffre <10):\n"); if (*p==*q) printf("symétrie axiale horizontale"); scanf("%d", &chiffre);} while(chiffre<0 || chiffre>=10) ; else printf("non symétrie "); n = nbr; system("pause"); } do{ rest = n%10; n = n/10; Exercice 5 (4 pts) if(rest==chiffre) occu++; }while(n); char * repeter(char *s, int n) printf(" le nombre d'occurences de %d dans %d est de %d ",chiffre, nbr, occu); {char *ch,*p; system("pause"); int lg, i; } lg =strlen(s); ch= (char*)malloc(((lg*n)+1)*sizeof(char)); Exercice 3 (4 pts) for(p=ch;*s!='\0';s++) int * fusionner( int *A, int N, int *B, int M) for (i=0;i<n;i++) *(p++)=*s; {int iA=0, iB=0, iAB=0, *AB; *p='\0'; AB = (int*)malloc((N+M)*sizeof(int)); return (ch); }