C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Structure of a C program
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Introduction Computer program: an ordered sequence of instructions whose objective is to accomplish a task. Programming: process of planning and creating.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
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.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It.
C Programming Lecture 4 : Variables , Data Types
C Tokens Identifiers Keywords Constants Operators Special symbols.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Introduction to Programming
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
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.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Chapter Topics The Basics of a C++ Program Data Types
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++.
Introduction to C Programming Language
Introduction to C Programming
Basic Elements of C++ Chapter 2.
Visit for more Learning Resources
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
פרטים נוספים בסילבוס של הקורס
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Variables in C Declaring , Naming, and Using Variables.
C Programming Getting started Variables Basic C operators Conditionals
Chapter 2: Introduction to C++.
C programming Language
Programming Language C Language.
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
DATA TYPES There are four basic data types associated with variables:
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Course Outcomes of Programming In C (PIC) (17212, C203):
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Getting Started With Coding
Presentation transcript:

C Programming Laboratory I

Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return a; } Comment Header file Decaration Program Body

Comment Do not want to compile this section There are 2 forms /* comment part */ // comment part used only borland C compiler /* This is comment */ /* For produce the good program, should Write comment every line of program */ //Or use line comment for Borland C

Preprocessing Directives (#) Use for inform compiler to do something before compiling #define#endif#error #ifndef#elif#if #include#else#ifdef #pragma#undef

#define Directive Define word expression or command #define Example #define TEN 10 #define PI #define R 2*PI #define MUCH 3*6+5 \ -(7*3)

#include Directive Read the according files to co-compile #include #include “filename” Example #include #include “sample.c”

Structure of module Program, written by C consisted of modules Main() is the principle module One program have to have one main() Module-type module-name(argument) { a sequence of commands; }

Identifiers Definition of all of name such as variable 1. Keywords 2. User-defined word Auto default floatregister structvolatile Break do forreturn switchwhile Case doublegotoshort typedef Char else ifsigned union Const enum intsizeof unsigned Continue externlongstatic void

Rule of User-defined word Case sensitive Character “ _ ” Number First with Character or “ _ ” Have to define before use Define in any command or expression Don ’ t same as KeyWord

Type of Identifiers Global Identifiers : define external a set of command Local Identifiers : define internal a set of command A B

DATA TYPE Size char-128 to 1271 Byte unsigned char 0 to 2551 Byte int to Byte unsigned int 0 to Byte long to Byte unsigned long0 to4 Byte float-3.4E+38 to 3.4E+384 Byte double1.7E+3088 Byte voidNo-specified / No-Value return -

constant Integer constant Floating constant Character constant Interger : Long int : L Hex Form : 0x7a 0xfe 0x e0 : 3.2e5 0.0E0 : 3.4E-8 ‘A’ ‘b’ ‘#’

Variables Name for calling the value in memory Format for define variables [, ]; Example char a,b,c; unsigned int d;

Expressions Expressions in form operand1 operator operand2 OperatorMeaningExpressionResult +Add Substract7 – 34 *Multiple7 * 321 /Divide7 / %Modulate7 % 31

Statements The complete command to instruct computer to do something Enclose with ; (semi-colon) Blank space is not important

Assignment Statements following Form It mean calculate expression in right side and assign in variable in left side = Expression;

Input & Output Character Code String Output Statement Input Statement

Character Code Character represent to computer in number,called ASCII Code ( American Standard Code for Information Interchange) 128 characters,7 Bits Extended ASCII Code 128 characters for special character such as Greek-Latin character, including Thai font Big program occurred when using more than 2 language or the language require more character such Chinese Language. Represent enclose with ‘ and ’ (qoute symbol) ‘a’ ‘4’ ‘\0’ ‘\n’

STRING A sequence of characters Represent enclose with “ and ” (double qoute) “Hello world!”

Output Statement command present string on monitor printf(charformat[,argument]); Example printf(“Hello World!”); a = 12; printf(“Hello! Number%d”,a);

Output Statement Type this program #include /* Call module stdio.h */ void main(void) /* Main function*/ { char *msg = “ ชื่อของนักศึกษา \n”; intid = รหัสนักศึกษา 4 ตัวท้าย ; printf(”%s student-code = %d \n”,msg,id); }

Input Statement Command get value from keyboard scanf(char-format[,address]); #include void main(void) { int date,month,year; printf(“Please enter date in dd/mm/yy :”); printf(“date :”); scanf(“%d”,&date); printf(“month:”); scanf(“%d”,&month); printf(“year :”); scanf(“%d”,&year); printf(“Date: %.2d/%.2d/%.2d\n”,date,month,year); }

งานปฏิบัติการ 5 จงเขียนโปรแกรมรับค่าความยาวฐานของ สามเหลี่ยมและความสูงของสามเหลี่ยมแล้วนำมา ประมวลผลหาค่าพื้นที่ของสามเหลี่ยม Input Base Length : 10 Input Height : 5 Output Area of Triangle = 25