Advertisement
icatalin

Untitled

Apr 29th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. //In fisierul numere.in se afla cel mult 5k numere reale. Scrieti un program care citeste nr. din fisier si afiseaza pe ecran numarul de ordine
  2. //al primei, respectiv ultimei linii pe care se afla cel mai mare numar din fisier.
  3. #include <fstream>
  4. #include <iostream>
  5. #include <climits>
  6.  
  7. using namespace std;
  8.  
  9. void main()
  10. {
  11.     ifstream f("numere.in");
  12.     ofstream g("date.out");
  13.     float max,x;
  14.     int p,u,i;
  15.     f>>x;
  16.     max=x;
  17.     p=1;
  18.     u=1;
  19.     i=1;
  20.     while (f>>x)
  21.     {
  22.         i++;
  23.         if (x>max)
  24.         {
  25.             max=x;
  26.             p=i;
  27.             u=1;
  28.         }
  29.         else
  30.         if (x==max)
  31.         u=i;
  32.     }
  33.     g<<p<<" "<<u;
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement