HI , this is a question purely related to C programming. I am calculating a division between two float numbers e.g 4.00 / 3.00. Now if i answer 1.3333 , the functions returns that it is wrong. i just want to know how to truncate in Float values in C ??? here is the copy of the code: float d1,d2,d3; main( ) { srand(time(0)); // Initialize random number generator. ans = 1; while ( ans != 0 ) { /// starting of For loop //////////////// wrg =0; for ( cnt=0;cnt<3;cnt++) { d1 = float(rand()%x+2 ); d2 = float(rand()%x+2) ; printf("\n\t Solve this %f / %f :.........\n", d1, d2 ); scanf("%f", &d3); divid_cheque(d1,d2,d3); }// ending for loop printf("\n\t Do you want to continue........\n"); printf("\n\t Type 1 = continue or 0 = to terminate \n"); scanf("\n\t%d", &ans); } printf("\n Total number of wrong answers : %d out of %d \n\n", wrg, cnt); return 0; } //////////////////////Division(/) Function defined////////////////////////////////////////////////////////////////// //unsigned int division( unsigned int y, unsigned int z, unsigned int x ) // unsigned int divid_cheque( unsigned int j, unsigned int k, float l) // int divid_cheque( float j, float k, float l ) int divid_cheque( float j, float k, float l ) { float as; as=j/k; if ( l== as ) printf("\n \t Right answer..........\n"); if ( l != as ) { printf(" \n \t << WRONG ANSWER >> \n"); printf("\n \t the right answer is = %f",as); wrg++ ; // incrementing counter for wrong answers } else return (wrg); } ////////////////////////////////////////////////////////////////////////////////////////////////
E
EmbdedCguru
@EmbdedCguru