Real World Application Classifying solutions as acidic or nonacidic

/* This program reads molar concentrations until end-of-file.  For
   each molar concentration mc, it computes the corresponding pH using
   the formula
         pH = - log10( mc )
   It then reports whether the solution is acidic (pH < 7) or nonacidic.
*/

#include 
#include 

main()
{
   float mc, ph;

   while( scanf("%f", &mc) != EOF ) {
      ph = - log10(mc);
      printf("\nMolar concentration = %e\n", mc);
      printf("pH = %f\n", ph);
      if (ph < 7.0) 
         printf("Acidic\n");
      else
         printf("Nonacidic\n");
   }
}

Previous slide Next slide Back to first slide View graphic version