Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. void mult(int *x1, int *y1, int *x2, int *y2){
  2. long long top = (*x1) * (*x2);
  3. long long bottom = (*y2) * (*y1);
  4. long long frac;
  5. if(bottom != 0||top != 0){
  6. frac = commonDiv(top,bottom);
  7. }else{
  8. frac = 1;
  9. }
  10. string sign = "";
  11. if(top * bottom < 0){
  12. sign = "-";
  13. }else{
  14. sign = "";
  15. }
  16. printf("%s%lld / %lldn",sign.c_str(),abs(top/frac),abs(bottom/frac) );
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22.  
  23. int numOp;
  24. scanf("%d", &numOp);
  25. getPrime(1,sqrt(100000));
  26. while(numOp != 0){
  27. int x1,x2,y1,y2;
  28. char op[2];
  29. scanf("%d %d %s %d %d", &x1, &y1, op, &x2, &y2);
  30. if( op[0] == '+'){
  31. add(&x1, &y1, &x2,&y2);
  32. }
  33. else if(op[0] == '-'){
  34. sub(&x1,&y1,&x2,&y2);
  35. }
  36. else if(op[0] == '/'){
  37. divi(&x1,&y1,&x2,&y2);
  38. }
  39. else{
  40. mult(&x1,&y1,&x2,&y2);
  41. }
  42. numOp--;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement