Don't like ads? PRO users don't see any ads ;-)
Guest

tri2

By: a guest on Aug 22nd, 2012  |  syntax: C++  |  size: 0.34 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include<fstream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.         int x,n;
  7.         ifstream fin("tri.in");
  8.         ofstream tri("tri.out");
  9.         ofstream rest("rest.out");
  10.         while(fin>>x)
  11.         {
  12.                 x*=2;
  13.                 n=int(sqrt(double(x)));
  14.                 if(n*(n+1)==x) tri<<x/2<<" ";
  15.                 else rest<<x/2<<" ";
  16.         }
  17.         fin.close();
  18.         tri.close();
  19.         rest.close();
  20.         return 0;
  21. }