Sunday, March 29, 2009

Write a program to add two fractions


/*Write a prg that adds two fractions.Your ouput need not be in terms*/

#include
int main(void)
{
int n1,n2,b1,b2,res1,res2;
printf("First Fraction \n");
printf("Enter the numerator : ");
scanf("%d",&n1);
printf("\nEnter the denominator : ");
scanf("%d",&n2);
printf("Second Fraction \n");
printf("Enter the numerator : ");
scanf("%d",&b1);
printf("\nEnter the denominator : ");
scanf("%d",&b2);
res1 = ((n1*b2) + (b1*n2));
res2 = (n2*b2);
printf("\nResult of two fraction %d/%d + %d/%d = %d/%d",n1,n2,b1,b2,res1,res2);
return 0;
}

No comments: