Then the program should close by using the closing parenthesis While reading

Then the program should close by using the closing

This preview shows page 3 - 6 out of 6 pages.

Then the program should close by using the closing parenthesis  } . While reading and printing the format characters for   integer   variables is   %d , for   float variables is  %f , for  double  variables is  %lf , for  character  variables is  %c Page 3 of 6
Image of page 3
While writing the formulas note that for addition  use  + , for subtraction  use  - , for multiplication  use  *  and for division  use  / . You can write any explanations for the reader of the program to understand the program by  enclosing them within the opening symbol  /*  and closing symbol  */. These explanations are  called as  comments. Example :   Write a simple program that  reads   an   integer   variable   a , a   float   variable   b , a   double variable  c , a  character  variable  d . Then it computes the value of a  float  variable  x  by using  the formula  x = a x b + c and prints  the value of  x and the character read in variable d . #include <stdio.h> /* the statement to include library file stdio.h */ void main (void) /* the main function declaration */ { int a ; /* integer variable declaration */ float b , x ; /* float variables declaration */ double c ; /* double variable declaration */ char d ; /* character variable declaration */ /*asking the user to enter the input values */ printf (“Enter the values for integer, float, double and character variables. \n”) ; /* reading of  input variables with format character */ scanf (“%d %f %lf %c”, &a, &b, &c, &d) ; x = a * b + c ; /* computing the value of x using arithmetic statements */ printf (“The character = %c The value of x = %f \n”, d, x) ; /* printing  the output values */ } // end of main Formatting Numbers in Program Outputs : Formatting means arranging the way the output should be printed either on the screen or in an  output file. Page 4 of 6
Image of page 4
Formatting values of type   int : To format an integer value write the   %nd   in the quoted parameter of the   printf statement, where  n  is the number of columns or places to be used for the display of digits.  n  is  called the  field width . Example : Let the variable  x  has  -234  as its value.  Then if the format is given as  %5d  the printed output is  b-234 , where  b  is a  blank Similarly,  %6d  will cause the printed output to be  bb-234 . So, if the field width is greater than 
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 6 pages?

  • Spring '10
  • zaman
  • printf, tab character

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes