SHARE
TWEET

Untitled

a guest Nov 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Name: Alon Doron, ID: 208957837 */
  2.  
  3. #define _CRT_SECURE_NO_WARNINGS
  4. #include <stdio.h>
  5.  
  6. struct Fraction
  7. {
  8.     int counter;
  9.     int denominator;
  10. };
  11.  
  12. int main() {
  13.     int m, n, a, b;
  14.     struct Fraction m_div_n, a_div_b, output;
  15.     char ch;
  16.  
  17.     printf("Enter \"m\" number: ");
  18.     scanf("%d", &m_div_n.counter);
  19.  
  20.     printf("Enter \"n\" number: ");
  21.     scanf("%d", &m_div_n.denominator);
  22.  
  23.     printf("Enter \"a\" number: ");
  24.     scanf("%d", &a_div_b.counter);
  25.  
  26.     printf("Enter \"b\" number: ");
  27.     scanf("%d", &a_div_b.denominator);
  28.  
  29.     printf("Enter \"ch\" character: ");
  30.     scanf(" %c", &ch);
  31.  
  32.     if (ch == '+') {
  33.         output.counter = (m_div_n.counter * a_div_b.denominator) + (m_div_n.denominator * a_div_b.counter);
  34.         output.denominator = m_div_n.denominator * a_div_b.denominator;
  35.     }
  36.  
  37.     if (ch == '-') {
  38.         output.counter = (m_div_n.counter * a_div_b.denominator) - (m_div_n.denominator * a_div_b.counter);
  39.         output.denominator = m_div_n.denominator * a_div_b.denominator;
  40.     }
  41.  
  42.     if (ch == '*') {
  43.         output.counter = m_div_n.counter * a_div_b.counter;
  44.         output.denominator = m_div_n.denominator * a_div_b.denominator;
  45.     }
  46.  
  47.     if (ch == '/') {
  48.         output.counter = m_div_n.counter * a_div_b.counter;
  49.         output.denominator = m_div_n.denominator * a_div_b.denominator;
  50.     }
  51.  
  52.     printf("The Output is: \n%d / %d = %f\n", output.counter, output.denominator,
  53.         ((float)output.counter / output.denominator));
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top