covertion of decimal into fraction 1

covertion of decimal into fraction

 /* IT IA A C CODE COVERT A DECIMAL INT0 NORMAL FRACTION AND MIXED FRACTION*/
      /* EXAMPLE   1.50 ->3/2  ->1 1/2*/

	 #include
	 void main()
	 {
	 	float f;
	 	
		int n1,n2,e,g,s,h,i;
	 	printf("enter the float value\n");
	 	scanf("%f",&f);
	 	n1=f*100;
	 	n2=100;                                                  
	 	if(n1>n2)
	 		h=n2;
	 	else
	 		h=n1;
	 		
	 		for(i=1;i<=h;i++)
	 			{
	 				if((n1%i==0)&&(n2%i==0))
	 				s=i;
				}
		 e=n1/s;
		 g=n2/s;
		 printf(" normal fraction become %d/%d",e,g);
		 printf("\n");
		 int z=e/g;
		 int y=e%g;
		 int x=e-y;
		 printf(" mixed fraction become %d %d/%d",z,y,x);
		 
	}
                             /* Submitted by akshaykonoor363@gmail.com*/
		

Here is what the above code is Doing:
1. First, it takes a float value from the user.
2. Then, it converts the float value into a fraction.
3. Finally, it converts the fraction into a mixed fraction.

Similar Posts