LOVEGUN

Exercice suite de nombres croissants (Esprit)

Oct 16th, 2021 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int t[20],n,i,c,maxc,d,r;
  7.     printf ("Saisir la taille du tableau: ");
  8.     scanf ("%d",&n);
  9.     for (i=0;i<n;i++)
  10.     {
  11.         printf ("T[%d]: ",i);
  12.         scanf ("%d",&t[i]);
  13.     }
  14.     i=0;
  15.     maxc=0;
  16.     do{
  17.         c=1;
  18.         while (t[i]<t[i+1] && i<n-1)
  19.         {
  20.             c++;
  21.             i++;
  22.         }
  23.         i++;
  24.         if (c!=1 && c>maxc)
  25.         {
  26.             maxc=c;
  27.             d=i-maxc;
  28.         }
  29.  
  30.     }while (i<n-1);
  31.     printf ("La plus long cycle est %d et la suite est : ",maxc);
  32.     for (i=d;i<=maxc+d-1;i++)
  33.     {
  34.       printf (" %d ",t[i]);
  35.     }
  36.  
  37.  
  38. }
  39.  
Add Comment
Please, Sign In to add comment