C Program To Add Two Fractions

C Program To Add Two Fractions. If you are looking for the addition of two fractions program in C, here in this tutorial we will help you to learn how to write a c program to add two fractions.

C Program To Add Two Fractions

Just copy paste the below source code to add two fractions in C compiler to test, how the source code works. Debug and learn how it works. Happy coding.

C Program To Add Two Fractions Source Code

/* C Program To Add Two Fractions - TwoFractions.C */

#include<stdio.h>
int lcm(int,int);

void main()
{
  int NM,NM1,DN1,NM2,DN2,LCM; //variable declaration
  clrscr();

  //Asking user to enter two numbers of fraction one
  printf("ENTER FRACTION-ONE (Numerator Denominator): ");
  scanf("%d%d",&NM1,&DN1); //reading two numbers

  //Asking user to enter two numbers of fraction two
  printf("ENTER FRACTION-TWO (Numerator Denominator): ");
  scanf("%d%d",&NM2,&DN2); //reading two numbers

  LCM = lcm(DN1,DN2); //lcm function
  //printf("LCM OF TWO NUMBERS IS %d",LCM);

  printf("FRACTION ADDITION IS : "); //
  printf("%d/%d + %d/%d = ",NM1,DN1,NM2,DN2);

  NM1=NM1*(LCM/DN1);
  NM2=NM2*(LCM/DN2);
  NM=NM1+NM2;

  printf(" %d/%d",NM,LCM);
  getch();
 }
  
 //lcm function logic
 int lcm(int N1,int N2)
 {
  static int TEMP = 1;
  if(TEMP % N2 == 0 && TEMP % N1 == 0)
  return TEMP;
  TEMP++;
  lcm(N1,N2);
  return TEMP;
 }

C PROGRAMMING EXAMPLES

  1. C Program To Add Two Numbers
  2. C Program To Reverse A Number
  3. C Program to Find Maximum and Minimum Numbers
  4. C Program to Read a Text File
  5. C Program to Convert Decimal to Hexadecimal
  6. C Program to Convert Decimal to Binary
  7. C Program to Convert Celsius to Fahrenheit
  8. C Program To Find Absolute Value
  9. Ternary Operator Program in C
  10. C Program For Addition Table Using For Loop
  11. Denomination Program in C
  12. C Program to Print Multiplication Table 
  13. C Program Array with Example
  14. Binary Search in C Program Using Recursion
  15. Bubble Sort in C Using Pointers
  16. Bubble Sort Program in C Using Recursion
  17. Bubble Sort Program in C Using Array
  18. Bubble Sort Program in C Using Function
  19. Bubble Sort Program in C Using Linked List
  20. Stack Push Pop Program in C Using Arrays

Leave a Reply

Your email address will not be published. Required fields are marked *