ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

Similar documents
ME 172. Sourav Saha. Md. Mahamudul Hossain Kazi Fazle Rabbi Saddam Hossain Joy Kamruzzaman Lecturer,Dept. of ME,BUET

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

ANSI C Programming Simple Programs

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

Unit 4. Input/Output Functions

BSM540 Basics of C Language

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

Data Types and Variables in C language

CS16 Exam #1 7/17/ Minutes 100 Points total

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

CC112 Structured Programming

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

VARIABLES AND CONSTANTS

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out

printf( Please enter another number: ); scanf( %d, &num2);

Have the same meaning as variables in algebra Single alphabetic character Each variable needs an identifier that distinguishes it from the others a =

Input/Output Week 5:Lesson 16.1

LECTURE 02 INTRODUCTION TO C++

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Chapter 2 THE STRUCTURE OF C LANGUAGE

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Programming and Data Structures

CS149: Elements of Computer Science. Fundamental C++ objects

C: How to Program. Week /Mar/05

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Chapter 2: Introduction to C++

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Lesson 3 Introduction to Programming in C

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Computers Programming Course 5. Iulian Năstac

UNIT-I Input/ Output functions and other library functions

Precedence and Associativity Table. % specifiers in ANSI C: String Control Codes:

The C++ Language. Arizona State University 1

Chapter 2 - Introduction to C Programming

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Fundamentals of C Programming

Chapter 3 Basic Data Types. Lecture 3 1

Basic Elements of C. Staff Incharge: S.Sasirekha

THE FUNDAMENTAL DATA TYPES

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Lesson 7. Reading and Writing a.k.a. Input and Output

Operators and Expression. Dr Muhamad Zaini Yunos JKBR, FKMP

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Display Input and Output (I/O)

BASIC ELEMENTS OF A COMPUTER PROGRAM

CSc Introduction to Computing

C Language, Token, Keywords, Constant, variable

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Structured Programming. Dr. Mohamed Khedr Lecture 4

Operations. Making Things Happen

Should you know scanf and printf?

Getting started with Java

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Multiple Choice Questions ( 1 mark)

CS242 COMPUTER PROGRAMMING

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Fundamentals of Programming Session 4

Exercise: Using Numbers

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

C - Basic Introduction

Fundamentals of Programming

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

Fundamentals of Programming Session 8

Fundamental of C programming. - Ompal Singh

Numerical Analysis First Term Dr. Selcuk CANKURT

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

C Program Structures

Basics of Programming

Introduction to C Language

Programming Fundamentals (CS-302 )

Data Types & Variables

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

BLM2031 Structured Programming. Zeyneb KURT

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

Arrays. Lecture 9 COP 3014 Fall October 16, 2017

Unit 3. Constants and Expressions

Fundamentals of C. Structure of a C Program

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

Lab Session # 1 Introduction to C Language. ALQUDS University Department of Computer Engineering

DEPARTMENT OF MATHS, MJ COLLEGE

Chapter 4: Basic C Operators

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

بسم اهلل الرمحن الرحيم

Programming in C++ 4. The lexical basis of C++

Number Systems, Scalar Types, and Input and Output

CS10001: Programming & Data Structures. Dept. of Computer Science & Engineering

Fundamental of Programming (C)

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Transcription:

ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1

Data Types and Modifier unsigned char 8 bits 0 to 255 char 8 bits 128 to 127 unsigned int 16 bits 0 to 65,535 int 16 bits 32,768 to 32,767 unsigned long 32 bits 0 to 4294967295 long 32 bits 2147483648 to 2147483647 float 32 bits 3.4*(10 38 ) to 3.4*(10 +38 ) double 64 bits 1.7*(10 308 ) to 1.7*(10 +308 ) 07/03/2011 ME 172 3 Bit and Byte Each piece of information stored within computer s memory is encoded ddas some unique combination of zero and ones. These 0/1 are called bits. 1 byte = 8 bits. 7 6 5 4 3 2 1 0 07/03/2011 ME 172 4 2

Variables All variables must be declared before they use. There are two places variables are declared Variable declared outside all functions called Global Variable, they can be accessed by any function in the program Variable declared inside a function called Local Variable, that can only be accessed by only the function in which it is declared Basic syntax is <Type> <Identifier>; Example int a; Where variables are declared? 07/03/2011 ME 172 5 Rules of declaring variables o Alphabetic character (a.z ; A..Z), digits (0,1 9), (_) and ($)can only be used in variable name. (int number) o 1st character must be letter, cannot be digit. (1_roll) o Both upper and lowercase are permitted o No space is allowed in the variable name (my name) o Keywords are not allowed (void, int, float etc.) o Variable name should not be greater than 31 char. 07/03/2011 ME 172 6 3

Format Specifier %d signed decimal Integer %u unsigned decimal integer %ld long integer %f floating point data type %lf double data type %Lf long double %e float data in exponential e notation %c single Character %s string pointer,prints characters until a null-terminator is pressed. %% prints the % character 07/03/2011 ME 172 7 scanf() function scanf function allows to accept input from standard din, generally the keyboard General form scanf( format_specifier,&variable); &variable means address ofthe variable int age; scanf ( %d, &age); 07/03/2011 ME 172 8 4

scanf() function More example float gpa; scanf ( %f, &gpa); char grade; scanf ( %c, &grade); double number; scanf( %lf, &number); 07/03/2011 ME 172 9 scanf() function More examples #include<stdio.h> d void main() { int num; float x; scanf ( %d %d, &num); scanf ( %f, &x); } scanf scanf ( %d %f, &num, &x); } 07/03/2011 ME 172 10 5

printf() function The printf statement allows to send output to standard out; standard dout is generally the screen printfgeneral form printf( format specifier, variable ); 07/03/2011 ME 172 11 printf() function Examples #include<stdio.h> void main() { int x = 10; printf( %d, x); printf( The value of x is %d, x); } Output is 10 The value of x is 10 07/03/2011 ME 172 12 6

Escape Sequences Escape Sequence Character Value \b Blank space \n New line \t Tab \\ Backslash \ Apostrophe \ Double quote 07/03/2011 ME 172 13 Formatted Output 07/03/2011 ME 172 14 7

Formatted Output 07/03/2011 ME 172 15 Exercise 1 Write a C program that will take input your student_id, cgpaand Equivalent grade from keyboard and will display the output in the following format My student id 200810001 My cgpa 3.50 Which Equivalent to A Hints: use long integer for student id 07/03/2011 ME 172 16 8

Exercise 2 Write a C program that will take input 322.54321 from keyboard and willdisplay the output in the following format 322.54 07/03/2011 ME 172 17 Exercise 3 Write a C program that will take input 8976 from keyboard and will display the output in the following format 8 9 7 6 0 0 8 9 7 6 07/03/2011 ME 172 18 9

Exercise 4 Write a C program that gives the following line as output. Declare three separate variables and use the corresponding format specifiers to print the desired output. The consecutive items should be apart from each other by a space equivalent to one tab. 3.456 99 A 07/03/2011 ME 172 19 Exercise 4 (do yourself) Write a C program that will take input your length and widthofa rectangle from keyboard and willdisplay the output in the following format Area of the rectangle is 50.00 07/03/2011 ME 172 20 10

math.h Some functions of math.h pow(b,e) sin(x) cos(x) tan(x) log(x) log10(x) () abs(x) and many others 07/03/2011 ME 172 21 That s all about today. Download course materials from www.mislam.info/me172.html 07/03/2011 ME 172 22 11