IvoSilva

[PROG1] Ficha 9 | Exercício 1

Dec 5th, 2011
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. int contaRepeticao (int v[], int n, int num)
  3. {
  4.     int i , j , soma , max = -999 ;
  5.     for (i = 0 ; i < n ; i++)
  6.     {
  7.         if (v[i] == num)
  8.         {
  9.             soma = 0 ;
  10.             for (j = i ; (j < n) && (v[j] == num) ; j++) soma++ ;
  11.             if (soma > max) max = soma ;
  12.         }
  13.     }
  14.     return max ;
  15. }
  16. int main ()
  17. {
  18.     int v[30] , n , num ;
  19.     for (n = 0 ; v[n - 1] != -1 ; n++)
  20.     {
  21.         printf ("Introduza número : ") ;
  22.         scanf ("%d" , &v[n]) ;
  23.     }
  24.     printf ("Número a pesquisar : ") ;
  25.     scanf ("%d" , &num) ;
  26.     printf ("Maior sequencia com números %d tem tamanho %d.\n" , num , contaRepeticao (v , n , num)) ;
  27.     return 0 ;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment