Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. //03 정수 연산
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <cstdlib>
  6. using namespace std;
  7.  
  8. void main()
  9. {
  10. ifstream inStream;
  11. int numTestCases;
  12.  
  13. inStream.open("input.txt"); // open input file
  14. if (inStream.fail())
  15. {
  16. cerr << "Input file opening failed.\n";
  17. exit(1);
  18. }
  19.  
  20. inStream >> numTestCases; // read the number of test cases
  21. for (int i = 0; i < numTestCases; i++)
  22. {
  23. int a, b;
  24.  
  25. int sum, diff, mul, div, mod, abs, upper, same;
  26. inStream >> a >> b;
  27.  
  28. sum = a + b;
  29. diff = a - b;
  30. mul = a*b;
  31. div = a / b;
  32. mod = a%b;
  33.  
  34. if (a > b)
  35. {
  36. abs = a - b;
  37. upper = a;
  38. }
  39. else
  40. {
  41. abs = b - a;
  42. upper = b;
  43. }
  44.  
  45. if (a == b)
  46. {
  47. same = 1;
  48. }
  49. else
  50. {
  51. same = 0;
  52. }
  53.  
  54. cout << sum << ' ' << diff << ' ' << abs << ' ';
  55. cout << mul << ' ' << div << ' ' << mod << ' '<<upper<<' '<< same<<' '<<endl;
  56.  
  57. }
  58.  
  59. inStream.close(); //close input file
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement