Lab 2 Variables in C.

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Lecture 1: Comments, Variables, Assignment. Definitions The formal (human-readable) instructions that we give to the computer is called source code The.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
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.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
How Create a C++ Program. #include using namespace std; void main() { cout
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
1 IPC144 Session 11 The C Programming Language. 2 Objectives To format a #define statement correctly To use a #define statement in a C program To construct.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
 Pearson Education, Inc. All rights reserved Formatted Output.
1 2 2 Introduction to Java Applications Introduction Java application programming –Display messages –Obtain information from the user –Arithmetic.
The char Data Type A char is a one byte integer type typically used for storing characters. Example: char oneLetter = ’D’; We enclose the character in.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Lab 3 Variables & Expressions. Basic Operations Addition + Subtraction – Multiplication * Division / Modulus %
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Chapter 3 Input and Output
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
COMP 102 Programming Fundamentals I Presented by : Timture Choi COMP102 Lab 011.
Variables Symbol representing a place to store information
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
Chapter 2. Variable and Data type
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
A Sample Program #include using namespace std; int main(void) { cout
+ 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.
USER INTERACTION AND VARIABLES Tarik Booker CS 290 California State University, Los Angeles.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Fundamentals 2.
Formatted Input and Output
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Variables Mr. Crone.
ECE Application Programming
Input/output.
By: Syed Shahrukh Haider
Computers & Programming Languages
C Formatted Input / Output Review and Lab Assignments
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Lecture 13 Input/Output Files.
Unit-2 Objects and Classes
Computers & Programming Languages
Chapter 2: Java Fundamentals
Chapter 2: Java Fundamentals
Conversion Check your class notes and given examples at class.
Data Type.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
CSCE 206 Lab Structured Programming in C
Variables and Constants
Presentation transcript:

Lab 2 Variables in C

Variables in C Character (one byte) Integer (2 bytes) char u; Integer (2 bytes) int a; Long Integer (4 bytes) long int a; Float (4 bytes) float x; Double (8 bytes) double z;

Variable Naming (Identifiers) Variable name includes: Letters a…z, A…Z Numbers 0…9 Underscore _ First character either letters (a…z, A…Z) or underscore ( _ ) Variable name doesn’t include: Spaces Other characters ! , @ : # … Reserved names (int, float, void … etc) A ≠ a

printf("format_string", argument_list); Printing Variables printf("format_string", argument_list); int a=898; float x=126.654; printf("%d %f\n", a, x); printf("a=%d x=%f\n", a, x); 898 126.654 a=898 x=126.654

Conversion Specification printf("a=%5d",a); printf("x=%6.2f",x); Field width a= 898 x=126.65 8 9 .Precision Field width 5 6 . 2 1

General Display Format % [flag] [field width] . [precision] Total=99.12345 %6.3f %7.3f %-7.3 99.123

Examples /* Lab2, student name, student ID */ #include <stdio.h> Void main(void) { int i; float x; double y; char q; // declaration i=325; x=345.65; y=5.010210210678; q=‘G’; // intialization Printf(“i=%d\ni=%5d\ni=%-5d\ni=%+5d\ni=%0d\n”,i,i,i,i,i); Printf(“\nx=%f\nx=%e\nx=%15.2e\nx=%15.4e\n”,x,x,x,x); Printf(“\ny=%lf\ny=%le\nq=%c\n”,y,y,q); }