Computer Science, asked by DaraDeekshitha, 5 months ago

C program to find the sum of three fractions​

Answers

Answered by mad210202
1

Answer:

C program to find the sum of three fractions​.

Explanation:

#include <stdio.h>

int main()

{

     int numerator1, denominator1,numerator2,denominator2,numerator3,denominator3,x,y,c,gcd_no;

   //To take user input of numerators and denominators

    printf("\nEnter the numerator for 1st number : ");

    scanf("%d",&numerator1);

    printf("\nEnter the denominator for 1st number : ");

    scanf("%d",&denominator1);

    printf("\nEnter the numerator for 2nd number : ");

    scanf("%d",&numerator2);

    printf("\nEnter the denominator for 2nd number : ");

    scanf("%d",&denominator2);

    printf("\nEnter the numerator for 3nd number : ");

    scanf("%d",&numerator3);

    printf("\nEnter the denominator for 3nd number : ");

    scanf("%d",&denominator3);

   //numerator

   x=(numerator1*denominator2)+(denominator2*numerator3)+(denominator3*numerator1);  

   //denominator

    y=denominator1*denominator2*denominator3;  

  // Trick part. Reduce it to the simplest form by using gcd.

  for(c=1; c <= x && c <= y; ++c)

  {

      if(x%c==0 && y%c==0)

         gcd_no = c;

  }

   printf("\nThe added fraction is %d/%d ",x/gcd_no,y/gcd_no);

   printf("\n");

 return 0;

}

Output:-

Similar questions