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
- C Program To Add Two Numbers
- C Program To Reverse A Number
- C Program to Find Maximum and Minimum Numbers
- C Program to Read a Text File
- C Program to Convert Decimal to Hexadecimal
- C Program to Convert Decimal to Binary
- C Program to Convert Celsius to Fahrenheit
- C Program To Find Absolute Value
- Ternary Operator Program in C
- C Program For Addition Table Using For Loop
- Denomination Program in C
- C Program to Print Multiplication Table
- C Program Array with Example
- Binary Search in C Program Using Recursion
- Bubble Sort in C Using Pointers
- Bubble Sort Program in C Using Recursion
- Bubble Sort Program in C Using Array
- Bubble Sort Program in C Using Function
- Bubble Sort Program in C Using Linked List
- Stack Push Pop Program in C Using Arrays