Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Compiled Languages (https://www.askmehelpdesk.com/forumdisplay.php?f=466)
-   -   Modify a simple C progam (https://www.askmehelpdesk.com/showthread.php?t=634238)

  • Feb 8, 2012, 02:56 AM
    Bill9_21
    Modify a simple C progam
    Modify the program so that the user enters both fractions at the same time, separated by a plus sign:

    Enter two fractions separated by a plus sign: 1/2 1/4

    The sum is 3/4



    #include
    #include

    Int main(void)
    {
    Int num1, denom1, num2, denom2, result_num, result_denom;

    Printf("Enter first fraction: ");
    Scanf("%d/%d", &num1, &denom1);

    Printf("Enter second fraction: ");
    Scanf("%d/%d", &num2, &denom2);

    Result_num = num1 * denom2 num2 * denom1;
    Result_denom = denom1 * denom2;
    Printf("The sum is %d/%d\n", result_num, result_denom);

    Return 0;
    }

  • All times are GMT -7. The time now is 12:51 PM.