Search C Program | nimishsoft@gmail.com

Convert Km to Meter, Centimeter or Millimeter

/*    Convert Km to Meter, Centimeter or Millimeter    */
#include<stdio.h>
int main()
{
 float km;
 char v;
 float ans;

 printf("K.M. : ");
 scanf("%f",&km);
 printf("KM will be changed in (M,s,m) : ");
 fflush(stdin);
 scanf("%c",&v);
 if(v=='M')
  ans=km*1000;
 if(v=='s')
  ans=km*100000;
 if(v=='m')
  ans=km*1000000;
 printf("Answer : %.2f",ans);
 return 0;
}

11 comments:

  1. Thanks for the convert km to m formulae in C

    km to m

    ReplyDelete
  2. GOOD JOB ADMIN, But it is Conditional Programs, so it could be under "Conditional Programs" as you have separated on site.

    ReplyDelete
  3. Why is it written fflush(stdin) and what is the function of fflush?

    ReplyDelete
    Replies
    1. It's a function which allows you to flush [clear] the input buffer. You might use this function if you are thinking that there might be some data in input buffer which can create problems for you while taking user inputs from stdin.

      Delete
    2. fflush function is used to flush the input buffer.

      Delete
    3. Will you please explain this program in detailed steps,

      Delete
  4. The C library function int fflush(FILE *stream) flushes the output buffer of a stream.
    Following is the declaration for fflush() function.

    int fflush(FILE *stream)

    ReplyDelete
  5. c language for new user, chapter wise complete theory and programm

    ReplyDelete