previous up next contents
précédent: Bases d'un langage algorithmique monter: UE33/UE43 - Opt1. Algorithmique D.E.U.G. 2ème Année suivant: Quelques exercices   Table des matières

Équivalence langage algorithmique / langage C

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\STAT...
...\VAR{a}\GETS 3
\END
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
/******* Mon joli programme ********/
/* Déclaration des variables */
int a; 
void main() {
  a = 1; 
  /* Une autre affectation... */ 
  a = 3;
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\STAT...
...\xspace \VAR{tab}[10]
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
int   i = 17;
float x;
char  c = '@';
int   test = 1 ;
float tab[10];

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\STAT...
...t ', \VAR{A}+1)
\END
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
{
  int a;
  scanf("%d",&a);
  printf("A+1 vaut %d\n", a+1);
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\IF{(...
...ETS$\VAR{a}^3$ \ENDIF
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
if(((x == .5) && (i % 2 == 1)) || (x/i < 3)) {
  printf("x vaut 1/2\n");
}
if(i >= 0) {
  a = i+1;
  b = a*a;
} else {
  a = i-1;
  b = a*a*a;
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\FOR{...
...to(\VAR{i})}
\ENDFOR
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
for (i = 0; i < N; i++) {
  Toto(i);
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\FOR{...
...to(\VAR{i})}
\ENDFOR
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
for (i = 1; i <= 100; i=i+5) {
  Toto(i);
}
\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\FOR{...
...to(\VAR{i})}
\ENDFOR
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
for (i = 23; i >=12; i--) {
  Toto(i);
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\STAT...
... = ',\VAR{acc})
\END
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
{
  int i,n,acc;
  acc = 0;
  scanf("%d",&n);
  for(i = 0; i <= n; i++) {
    acc = acc + i*i*i ;
  }
  printf("Somme cubes de 1 à %d : %d\n",n,acc);
}

\begin{boxedminipage}{.9\linewidth}%
\begin{algorithmic}[1]%
\begin{sf}
\FUNC...
...xspace
\ENDIF
\END
%
\end{sf} \end{algorithmic}%
\end{boxedminipage}%
\par
    
int pas_premier(int n) {
  int j = 2;
  while((j < n) && (n % j != 0)) {
     j++;
  }
  if(j == n) {
    return 1;
  } else {
    return 0;
  }
}


previous up next contents
précédent: Bases d'un langage algorithmique monter: UE33/UE43 - Opt1. Algorithmique D.E.U.G. 2ème Année suivant: Quelques exercices   Table des matières
Arnaud Legrand
2003-08-18