Search This Blog

Thursday, 6 November 2014

Managing Formatted and Unformatted I/0 in C!

0 comments

FAQ on Formatted and Unformatted I/O in C!


Distinguish between the following:  getchar() and getche()

getch() : Reads a character and never waits for Enter key. Just getch processed after getting any key pressed and it never echoes the character on screen which u pressed. 

getche() : it works same as getch() but it echoes on screen. 

getchar() : It works differently from the other two. Whenever you press any key these are kept in Buffer.  After hitting Enter key, the first character gets processed and it echoes on the screen.

Write single C Statements for the following:
  1. Declare variables x,y and z to store floating point value
  2. Display the product of 34.54 and 5.46
  3. Display the quotient and remainder when 453 is divided by 34
  4. Prompt the user to type an integer number
  5. Read an integer variable k, that has been declared earlier
  6. Read an integer variable k, and a character variable ch that has been declared earlier
  7. Display float variable x with an accuracy of three places after the decimal point
  8. Display integer number k with a field width of 7 columns
  9. Display the character whose ASCII number is 95
Answer:
  1. float x,y,z;
  2. printf(“%f”, 34.54 * 5.46);
  3. printf(“%d%d”, 453/34, 453%34);
  4. printf(“Type an integer number : ”);
  5. scanf(“%d”, &k);
  6. scanf(“%d %c”, &k, &ch);
  7. printf(“%10.3f”, x);
  8. printf(“%7d”, k);
  9. printf(“%c”, 95);

Leave a Reply