nucLeaRsc2

Untitled

Jul 7th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int main()
  5. {
  6.     int v,max,nr=1,nam;
  7.     printf("Introduceti sirul de elemente:\n");
  8.     int rez = scanf("%i", &v);
  9.     if(!rez)
  10.     {
  11.         do
  12.         {
  13.             fflush(stdin);
  14.             printf("Introdu o valoare corecta:");
  15.             rez = scanf("%i", &v);
  16.         }while( !rez );
  17.     }
  18.    
  19.     max = v;
  20.     while(scanf("%i",&v))
  21.     {
  22.         if (v > max)
  23.         {
  24.             max = v;
  25.              nam = 1;
  26.         }      
  27.         else if ( v == max)
  28.         {
  29.             max =v;
  30.               nam++;
  31.         }
  32.        
  33.        nr++;
  34.     }
  35.     printf("Numarul de aparitii al maximului este %i,Lungimea sirului este %i,Maximul este %i",nam,nr,max);
  36.     fflush(stdin);
  37.     getch();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment