1 / 9

C Programming

C Programming. printf. int printf ( const char * format, ... ); printf (&quot;Characters: %c <br>&quot;, 'a'); printf (&quot;Decimals: %d %f<br>&quot;, 1977, 3.14);. Printf - float. %f – floating point. Displays upto 6 decimal places. %0.2f- displays 2 decimal places

fiona
Download Presentation

C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Programming

  2. printf • intprintf ( const char * format, ... ); • printf ("Characters: %c \n", 'a'); • printf ("Decimals: %d %f\n", 1977, 3.14);

  3. Printf - float • %f – floating point. Displays upto 6 decimal places. • %0.2f- displays 2 decimal places • %5.1f- displays 4 digits including one after decimal point. If less digits are there then it gives spaces instead • %05.1f- displays 4 digits including one after decimal point. If less digits are there then it gives leading zeros.

  4. Printf – decimal • %5d- displays a the value. If number of digits is less than 5 then leading spaces are given. • %-5d- here trailing spaces are given. • %05d- here instead of spaces zeros are given.

  5. Scanf • Reads data from standard input and stores them according to the parameter format into the locations pointed by the additional arguments. • Eg: -inti; scanf ("%d",&i);

  6. Coding standards • Variable • Each variable must strictly be named in a meaningful way • only one declaration of one variable in one line • Eg: -inttotal_marks; inttotalmarks; • File Name • Filenames should be all lowercase and can include underscores (_) or dashes • Eg:- helloworld.c or hello_world.c

  7. Coding standards • Comments • Meaningful comments and should be proper sentences • No spelling mistakes in comments • Indenting • Two spaces should be used. • Line length • Max 80 characters per line

  8. Question 1 • Swap two variables using a temporary variable. • Input • Enter integer value 1- 10 • Enter integer value 2- 20 • Output • Value 1= 10 • Value 2= 20 • After Swapping • Value 1= 20 • Value 2= 10

  9. Question 2 • Compute volume of a cylinder • Input • Enter the radius of cylinder (float) • Enter height of cylinder in float • Output • Volume of the cylinder(round off to 2 decimal places) =

More Related