PDA

View Full Version : Modify a simple C progam


Bill9_21
Feb 8, 2012, 02:56 AM
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;
}