C Programming Mr. KAJAL MAJI ASSISTANT PROFESSOR DEPARTMENT OF PHYSICS

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Java Planning our Programs Flowcharts Arithmetic Operators.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Introduction to programming Language C, Data Types, Variables, Constants. Basics of C –Every program consists of one or more functions and must have main.
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to Computer Algorithmics and Programming Ceng 113 Variables and Operators in C.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
C programming: Variables, Expressions part II. Data Types of Arithmetic Expressions Relational Expressions Logical Expressions Multiple Assignments Compound.
CIS Computer Programming Logic
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
Chapter 3: Data Types and Operators JavaScript - Introductory.
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.
C Programming n General Information on C n Data Types n Arithmetic Operators n Relational Operators n if, if-else, for, while by Kulapan Waranyuwat.
Introduction to Computer Systems and the Java Programming Language.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
1 Programming a Computer Lecture Ten. 2 Outline  A quick introduction to the programming language C  Introduction to software packages: Matlab for numerical.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Types of Operator Arithmetic operator Relational operator Logical operator Assignment operator Increment or decrement operator(unary) Bitwise operator.
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
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.
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.
SCP1103 Basic C Programming SEM1 2010/2011 Arithmetic Expressions Week 5.
Fundamental Data Types and Storage Classes: A C language programmer has to tell the system before-hand, the type of numbers or characters he is using in.
Basics of ‘ C ’ By Gaikwad Varsha P. Asst. Prof. Information Technology Dept. Govt. College of Engg. Aurangabad.
Arithmetic Expressions
CSCE 206 Structured Programming in C
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
BASIC ELEMENTS OF A COMPUTER PROGRAM
INSPIRING CREATIVE AND INNOVATIVE MINDS
Tokens in C Keywords Identifiers Constants
Revision Lecture
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
By: Syed Shahrukh Haider
Introduction to C Programming
11/10/2018.
Operators and Expressions
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Basics of ‘C’.
Introduction to C Programming
Lectures on Numerical Methods
Lecture3.
Chapter 3 Operators and Expressions
C – Programming Language
Operator and Expression
OPERATORS in C Programming
DATA TYPES There are four basic data types associated with variables:
C Language B. DHIVYA 17PCA140 II MCA.
Introduction to C Programming
OPERATORS in C Programming
INTRODUCTION TO C.
Introduction to Pointers
Getting Started With Coding
Presentation transcript:

C Programming Mr. KAJAL MAJI ASSISTANT PROFESSOR DEPARTMENT OF PHYSICS B.B. COLLEGE ASANSOL

Dept. of Physics, B.B.College Asansol What is C Program? A sequence of logically related instructions that enables the computer to perform a complete task is known as a program. A computer can only understand instructions written in binary form i.e. 0 and 1. A program written in binary form is referred to as machine language. Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Two types of language are used 1. Low level language 2. High level language Low level language are machine and assembly languages. High level language are FORTRAN, COBOL etc. Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol What is Compiler? A high level language is translated into machine language by using a program in the memory. A computer program written in high level language is known as source program. This program when translated into machine language is called an object program. Dept. of Physics, B.B.College Asansol

Character, Identifiers and Keywords Characters: A to Z, lowercase letters a to z. The digit 0 t0 9. Special characters: #,@,&,%,(),*, ; etc. Combinations characters \b,\n, \t, etc Keywords: auto, char, else, for, float, goto, int, if, retrun, void, while, const. Identifiers: gross, sum , name, area, name. Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Variables Variables refer the objects that can be stored in computer’s memory locations. Variables are named (identifiers). Variables must be declared and initialized. Variables can store data of various types. Some basic data types are char characters (1/2 bytes) int integers (2/4 bytes) float rationals (4 bytes) double rationals(8 bytes Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Declaration Declarations have form type var1, var2, var3; Merely announces the data type to be associated with a variable Examples char name; int a,b; float c,d; Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Array An array is a collective name of variables of the same data type. The individual variable making up an array is called an element of the array. Example: roll[1], roll[1]……….roll[20] Dept. of Physics, B.B.College Asansol

Operators and Expressions An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations of data variables. There are five types of operators: 1. Arithmetic operators 2. Relational operators 3. logical operators 4. Assignment operators 5. Unary operators Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Arithmetic operators + addition - subtraction * multiplication / division % percentage Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Relational operators a>b a greater than b a>=b a greater than or equal to b a< b a less than b a<=b a less than or equal to b a==b a equal to b a ! =b a equal to b Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol logical operators && logical AND ‖ logical OR ! logical NOT Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Assignment operators x= x+3 x+=3 x=x-3 x-=3 x=x*(n+2) x*=n+2 x=x/3 x/=3 x=x%3 x%=3 Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Unary operators ++x or x++ increments x by 1 -- x or x-- decrements x by 1 -x negates the value of x Example; x=4; y= ++x; y=5; Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Library Functions main (): Every c program must have function main() which may access (call) other function thus main () is a calling function. Input and output function: get char: Input function variable name= getchar (); scanf : Input function scanf(“control string”, argument1); Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Example: int x; float y; scanf(“%d,%f”,&x,&y); putchar: output function. putchar(ch); printf: output function. printf(“control string”, argument 1); printf(“%d %f”,x,y); Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol If-else statement It is used to carry out a logical test and then take one of two possible actions depending on the outcome of the test. if (test expression) statement 1 else statement 2 Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Example: y=x4 if x>2 = x+3 otherwise C-program: …………….. if (x>2) y=pow(x,4); else y=x+3 ……………… Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Looping In C language looping cab be done by using while, do while and for statements 1. while loop: while (test condition) { body of the loop } Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Example: ……… sum=0; n=1; while (n<=100) { sum=sum+m; n=n+1; } Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol 2. Do while loop: do { body of the loop } while (test condition) Example: int num=0; printf(“%d\n”,num); ++num; while(num<=11) Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol 3. for loop: for( initialization; test condition; increment) { body of the loop } Example: ………. for (i=0; i<4;i++) printf(“%d”.i); Dept. of Physics, B.B.College Asansol

Algorithm and Flowchart To write a program for a particular problem one must fully understand the nature of the problem, the kind of data to be given as input, kind of outputs need and the constraints and conditions under which the program has to operate. Depending on these one has to decide a solution procedure. Flowchart is a pictorial representation of an algorithm. Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Example: Let us consider the algorithm and flowchart for the problem of finding the larger of two numbers. Algorithm: Step 1 : Start the process by declaring two variables a and b. Step 2 : Give the inputs and store them in the Step 3 : Check, if a>b. If the answer is ‘yes’, go to step 4. Otherwise go to step 5. Step 4 : Print “a is greater than b” and go to step 6. Step 5 : Print “b is greater than a” and go to step 6. Step 6 : Stop. Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Flowchart: Start Declare variables a,b Input a,b and store their values Is a>b? NO Yes Print Print b>a a>b Stop Stop Dept. of Physics, B.B.College Asansol

Example: Area of the Sphere #include<stdio.h> main() { float r=5, Area; Area= 4*3.41*r*r; printf(“The area of the sphere is %f\n”,area); } Dept. of Physics, B.B.College Asansol

Dept. of Physics, B.B.College Asansol Example: Matrix #include<stdio.h> main() { int a=1,i,j,m, n,mat[10][10]; printf("Enter the row numbers : \t"); scanf("%d",&m); printf("Enter the columb numbers : \t"); scanf("%d",&n); printf("Enter the elements of the matrix :\t"); for(i=0;i<m;i++) for(j=0;j<n;j++) scanf("%d",& mat[i][j]); printf("The given matrix is: \n"); printf("%d\t",mat[i][j]); printf("\n"); } Dept. of Physics, B.B.College Asansol