C Programming. printf int printf ( const char * format,... ); printf ("Characters: %c \n", 'a'); printf ("Decimals: %d %f\n", 1977, 3.14); specifierOutputExample.

Slides:



Advertisements
Similar presentations
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Advertisements

 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
Introduction to C Programming CE Lecture 2 Basics of C programming.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Basic Input/Output and Variables Ethan Cerami New York
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
C Programming Lecture 4. Tokens & Syntax b The compiler collects the characters of a program into tokens. Tokens make up the basic vocabulary of a computer.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
(1 - 2) C Language Elements H&K Chapter 2 Instructor - Andrew S. O’Fallon CptS 121 (August 28, 2015) Washington State University.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
C Tokens Identifiers Keywords Constants Operators Special symbols.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
C Programming – Part 6 File Input and Output
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Basic I/O in C Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens Stream Model of I/O header file: A stream provides a connection.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
E-1 University of Washington Computer Programming I Lecture 5: Input and Output (I/O) © 2000 UW CSE.
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
CS 1704 Introduction to Data Structures and Software Engineering.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Formatted Input and Output
Chapter Topics The Basics of a C++ Program Data Types
Input/output.
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Lecture 13 Input/Output Files.
Chapter 4 Managing Input and Output Operations
Conversion Check your class notes and given examples at class.
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

C Programming

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

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.

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.

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 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.

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

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

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

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) =