Data Types Session 2.  Primitive data types  int, float, double, char  Aggregate data types  Arrays come.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Fundamentals of Computer and programming in C
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advanced Input, Process and Output Commands Session 3.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
C Language.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Arrays and Strings.
Computer Programming w/ Eng. Applications
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Sort the given string, without using string handling functions.
By Senem Kumova Metin 1 POINTERS + ARRAYS + STRINGS REVIEW.
Lecture 2 Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Lab 5 rC language Elements rVariables Declarations and Data Types rGeneral Form of a C Program rArithmetic Expressions rFormatting Numbers rExercises Note:
CMT Programming Software Applications
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Introduction to C language
Basic Elements of C++ Chapter 2.
Basic Input - Output. Output functions  printf() – is a library function that displays information on-screen. The statement can display a simple text.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CSCI 130 Chapter 3. Variables & Names Variable Declarations: –reserve a storage location in memory –identify the name of the variable –identify the type.
Introduction to Programming
Primitive Variables.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java Lecture 21 Arrays – Part 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Numbers in ‘C’ Two general categories: Integers Floats
Chapter Topics The Basics of a C++ Program Data Types
User Interaction and Variables
BASIC ELEMENTS OF A COMPUTER PROGRAM
LESSON 3 IO, Variables and Operators
Yanal Alahmad Java Workshop Yanal Alahmad
Basic Elements of C++.
Revision Lecture
Lecture2.
Java Programming: From Problem Analysis to Program Design, 4e
By: Syed Shahrukh Haider
Basic Elements of C++ Chapter 2.
Visit for more Learning Resources
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.
Chapter 2: Java Fundamentals
WEEK-2.
Course Outcomes of Programming In C (PIC) (17212, C203):
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Data Types and Arithmetic in C
Presentation transcript:

Data Types Session 2

 Primitive data types  int, float, double, char  Aggregate data types  Arrays come under this category  Arrays can contain collection of int or float or char or double data  User defined data types  Structures and enum fall under this category. Data types in C 2

 Simple Data Type  int  integer  bil. bulat  float  floating point  bil. pecahan  char  character  hanya 1 digit  char[pj]  string  lebih dari 1 digit  How to declare  int jml_anak;  float nilai_mhs,rata2;  char sex,status;  char nm_mhs[20],almt[35]; How to Declare 3

 Variables are data that will keep on changing  Declaration > >; int a;  Definition >= >; a=10;  Usage > a=a+1;//increments the value of a by 1 Variables 4

 Should not be a reserved word like int etc..  Should start with a letter or an underscore(_)  Can contain letters, numbers or underscore.  No other special characters are allowed including space  Variable names are case sensitive  A and a are different. Variable names- Rules 5

 Variable Name for a memory object. Variable names must start with letters and contain letters, digits, and underscores. a, b, i, j, counter, number_of_points, c1234, …  Type What the variable represents. Could be of integer, floating point number, character, string, and many others. int, float, double, char, …  Declaration Tells compiler about variables and their type. int i,j; float sum; Variables 6

 It’s NOT a string anymore.  It is seemed as a series of characters, which is a character array.  The number of the character array is just the same as the number of letters of the word or sentence plus one.  The one more element is “\0” which is printed as “\n” by gets and printed as “”(NULL) by other words. What’s string in turbo C 7

Numeric Types intinteger floatfloating point charcharater (a very shot integer) short or short intshort integer long or long intlong integer doublelong floating point long doublevery long floating point 8

Reading Inputs 1.#include 2.#include 3.void main() 4.{ float bil1,bil2,hasil; //deklarasi variabel 5. clrscr(); //membersihkan layar 6. printf("Please input the first number : "); scanf("%f",&bil1); 7. printf("Please input the second number: "); scanf("%f",&bil2); 8. hasil = bil1 * bil2; //proses 9. printf(“bil1 * bil2 = %f\n“,hasil); //cetak hasil kali 10. getch(); //berhenti sebentar sampai ditekan tombol 11.} 9 printf(“Hasil Kali dari %f dengan %f adalah %f “,bil1,bil2,hasil);

Assignment 1./* Arithmetic operators */ 2.#include 3. #include 4.void main() 5.{ 6. int a,c; 7. int b=4; 8. a=3; 9. c=a+b; 10. printf(“Sum: %d + %d -> %d\n”,a,b,c); 11. a++;b--; 12. prinf(“Now a=%d and b=%d\n”,a,b); 13.} 10

 Write a program to calculate the average of three floating point numbers. Using scanf function Task 2 11 Buat program untuk meng-input-kan tiga buah bilangan pecahan sembarang kemudian hitung dan cetak rata-rata dari tiga bilangan tersebut.