Download presentation

Presentation is loading. Please wait.

Published byAron Bobby Modified about 1 year ago

1
C Programming

2
printf int printf ( const char * format,... ); printf ("Characters: %c \n", 'a'); printf ("Decimals: %d %f\n", 1977, 3.14); specifierOutputExample cCharactera d or i Signed decimal integer392 sString of characterssample uUnsigned decimal integer7235 f Decimal floating point392.65

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: - int i; scanf ("%d",&i); typeQualifying Input cSingle character: Reads the next character. dDecimal integer: Number optionally preceded with a + or - sign. e, E, f, g, G Floating point: Decimal number containing a decimal point, optionally preceded by a + or - sign and optionally folowed by the e or E character and a decimal number. Two examples of valid entries are -732.103 and 7.12e4 s String of characters. This will read subsequent characters until a whitespace is found (whitespace characters are considered to be blank, newline and tab). uUnsigned decimal integer.

6
Coding standards Variable – Each variable must strictly be named in a meaningful way – only one declaration of one variable in one line – Eg: -int total_marks; int totalmarks; 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) =

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google