Question
make a code for the additions of fractions. use the attached code to find LCM.

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int Icm(int, int); int main() int n1, n2, min Multiple; printf(Enter two
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Code to Copy

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int lcm(int, int);
int gcd(int, int);

int main(){

int num1, num2, num3, den1, den2, den3, minMultiple;

//Taking input fractions for sum
printf("Enter first fraction: ");
scanf("%d%d", &num1, &den1);
printf("Enter second fraction: ");
scanf("%d%d", &num2, &den2);

// Finding LCM of den1 and den2
den3 = lcm(den1,den2);
  
// Changing the fractions to have same denominator
// Numerator of the final fraction obtained
num3 = (num1)*(den3/den1) + (num2)*(den3/den2);
  
//Finding GCD of num3 and den3 to convert result into lowest term
int cd = gcd(num3, den3);
//Converting to lowest term
num3 = num3 / cd;
den3 = den3 / cd;
  
//Printing result
printf("Sum of %d/%d and %d/%d is %d/%d.\n",num1, den1, num2, den2, num3, den3);
return 0;
}

//Finding LCM to compute sum of fractions
int lcm(int n1, int n2){
  
int minMultiple = ( n1 > n2) ? n1 : n2;
//Always TRUE
  
while(1){
  
if (minMultiple % n1 == 0 && minMultiple % n2 == 0){
return minMultiple;
}
  
++minMultiple;
}
}

//Finding greatest common divisor to convert result in lowest term
int gcd(int n1, int n2)
{
if (n2 != 0)
return gcd(n2, n1%n2);
else
return n1;
}

Program Screenshot

1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 4 5 int lcm(int, int); int gcd(int, int); 7. int main() { int numi, nu

den = dens / cd; //Printing result printf(Sum of %d/%d and %d/%d is %d/%d.\n, num1, den1, num2, den2, num3, den3); return 0

Program Output

25 i nt cd = gcanums, dens) input Enter first fraction: 5 20 Enter second fraction: 10 80 Sum of 5/20 and 10/80 is 3/8. ... P

input Enter firsta fraction: 24 Enter second fraction: 36 Sum of 2/4 and 3/6 is 1/1. - ..Program finished with exit code 0 Pr

Add a comment
Know the answer?
Add Answer to:
make a code for the additions of fractions. use the attached code to find LCM. #define...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • #define minl (x, y) ( (x < y) ? x : y) #define min 10 #include...

    #define minl (x, y) ( (x < y) ? x : y) #define min 10 #include <stdio.h> int min2(int x, int y) { if (x < y) return x; else return y; } main() { int a, b; scanf("%d %d", &a, &b); if (b < min) printf("input out of range\n"); else { a = minl(a, b++); printf("a = %d, b %d\n", a, b); a = min2(a, b++); printf("a = %d, b %d\n", a, b); } } ------------------------- 1 Give the...

  • i need flowchart for the following c code #include <stdio.h> int main() {     int n,...

    i need flowchart for the following c code #include <stdio.h> int main() {     int n, i, sum = 0;     printf("Enter an integer: ");     scanf("%d",&n);     i = 1;     while ( i <=n )     {         sum += i;         ++i;     }     printf("Sum = %d",sum);     return 0; }

  • Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) {...

    Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }

  • Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) {...

    Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b,c; scanf("%d",&a); scanf("%d",&b); c=a|b; printf("%d|%d=%d\n",a,b,c); return 0; }

  • C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure...

    C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float aver...

    Do you have a flowgorithim flow chart for this code? #include <stdio.h> int main() { int num,i=0,sum=0; float average; int customerNumbers[num]; int customerSales[num]; printf("How many customers do you want to track?\n"); scanf("%d",&num); while(i<num) { printf("Enter the customer number. "); scanf("%d",&customerNumbers[i]); printf("Enter the sales for the customer "); scanf("%d",&customerSales[i]); i++; } printf("Sales for the Customer"); printf("\nCustomer Customer"); printf("\nNumber Sales"); for(i=0;i<num;i++) { printf("\n %d \t %d",customerNumbers[i], customerSales[i]); sum=sum+customerSales[i]; } average=(int)sum/num; printf("\n Total sales are $%d",sum); printf("\n Average sales are $%.2f",average); printf("\n --------------------------------------------");...

  • Create a functional ATM using the code base given in the example. You must use the...

    Create a functional ATM using the code base given in the example. You must use the routines provided in the code base example. Failure to follow the directions will result in an 'F' the example is down below! /* * @desc: Simple ATM machine * @duedate: 23-April-2019 * * * */ #include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> char menu(); char transaction_menu(); /* Verifies the Pin Entered match the PIN on record */ int validatePin(int); /* Verifies the funds...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT