Getting Started With Coding

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
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?
Basic Input/Output and Variables Ethan Cerami New York
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
By: Mr. Baha Hanene Chapter 4. LEARNING OUTCOMES This chapter will cover learning outcome no. 2 i.e. Use basic data-types and input / output in C programs.
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.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
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.
Week 1 Algorithmization and Programming Languages.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
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.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Bill Tucker Austin Community College COSC 1315
Numbers in ‘C’ Two general categories: Integers Floats
Chapter 1.2 Introduction to C++ Programming
CSCE 206 Structured Programming in C
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Computing Fundamentals
Basic Elements of C++.
Revision Lecture
ICS103 Programming in C Lecture 3: Introduction to C (2)
Getting Started with C.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
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 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
INPUT & OUTPUT scanf & printf.
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Govt. Polytechnic,Dhangar
Chapter 2 - Introduction to C Programming
WEEK-2.
Chapter 2 - Introduction to C Programming
Variables in C Topics Naming Variables Declaring Variables
CSCE 206 Lab Structured Programming in C
DATA TYPES There are four basic data types associated with variables:
Variables in C Topics Naming Variables Declaring Variables
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Variables and Constants
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Getting Started With Coding KIC 11/20/2019 Department of Information Technology. Introduction to Computer Programming Lec 3 Getting Started With Coding Introduction to Computer Programming 11/20/2019 Introduction to Computer Programming

Outlines Introduction to Programming Stages & Steps of Writing Programs Variables in C Data types Declarations Format Specifiers Assignment Statements Input Statement

Introduction to Programming A language which is used to instruct computer to perform different tasks according to the requirements. Every programming language has following basic things. Declarations Assignments Control Statements I/O (Input/output) Statements

Introduction to Programming Any programming language consists of its own keywords and syntax rules that distinguishes it from other programming languages. If you want to program in a specific language, you need the compiler of this specific language. For example, C language compiler translates programs written in C language to machine language.

Stages & Steps of Writing Programs Specification Design Coding Testing Documentation Keep it clear & simple Keep it short Think it through in advance Maintenance

Sample Program Explanation #include<stdio.h> int main() { printf(“Hello to programming”); printf(“\n Welcome at KIC”); printf(“\t at Spring2014”); } Header File used for Input / Output Main Function Necessary to start any C program printf is used to display the text & variable values stored in the memory locations. Function Start Output Statement used to display on screen \n Start New Line \t Give Space between text Function End

Sample Program Explanation #include <stdio.h> int main() { int a,b,c; a=2; b=5; c=a+b; printf("c=%d",c); } Header File Main Function Variable Declaration Function Body Assignment Statements Output

Variables in C 1. int 2. float 3. char In computer programming, a variable is a name given to some known or unknown quantity or value, for the purpose of allowing the name to be used independently of the value it represents [Data Type] [Variable Name] ; Data Types: In C programming there are more data types but we generally use the following data types. 1. int 2. float 3. char

Variables in C Variable Name: You can give any name to the variables in c but there are few rules for writing variable names. (A-Z) The first character must be a letter Space is not allowed between names of identifiers (&*^%$#@) Special symbols are not allowed in identifier names - Hyphens are not allowed in identifier names however underscores _ can be used (int, float, private etc.) The reserve words are not allowed in identifier names.

Variables in C Some valid identifiers / variable names hello j9 box22a get_data bin3d4 count Some reserve words (can’t be used as identifier): private else static int const float

Ex Variable Names velocity velocity freda freda time-of-day int tax_rate x2 4x first value radio@4 emp. velocity freda time_of_day INVALID tax_rate x2 x4 first_value radio4 emp RIGHT RIGHT RIGHT RIGHT RIGHT WRONG WRONG WRONG WRONG

Ex Identifiers X_ray 7_UP x AR*EA x _No A9 a-a x b6.1 x

Data Types In C Type Length Range int 16 bits -32768 to 32767 float 1e-38 to 1e+38 char 8 bits -128 to 127 unsigned int 0 to 65535 long int -2147483648 to 2147483647 unsigned long 0 to 4294967295 double 64 bits 1.7*(10**-308) to 1.7*(10**+308) 1.7*(E-308) to 1.7*(E+308) long double 80 bits 4.4*(10**-4932) to 1.1*(10**+4932)

Declarations The declaration means list all the variables (used for inputs and outputs) for one program in start. In declaration we have to tell the types of variables also. If we have more than one types of variables in one program then we have to mention them separately in the start. int x ; int x,y; The difference in variables and constants is, the value of variable can be changed within a program but the value of constant can’t be changed within a program.

Ex Declarations We usually declare all variables inside main function for example: #include<stdio.h> int main() { int avar ; int salary ; float percentage ; } Data Type Variable Name Semi Colon (every C statement ends with a semicolon ;)

Data Type Format Specifiers int %i , %d float %f char %c double long int %li These format specifiers we use in Input / Output statements.

Floating Point Use the keyword float to declare float variables Use the float data type when you know the variable will hold values that has decimal point. The range of float numbers is from 1e-38 to 1e38 To display float numbers use %f printf(“%f”, 12.1); 12.1 Show the output obtained from: printf(“%.3f”, 41.57467); 41.574

Double Numbers Charachters The keyword double is used to define double numbers Double values have the range 1E-308 to 1E+308 printf(“%lf”, 132.145); Charachters Characters are letters and symbols When you need to store letters, use character variable. Use the keyword char to declare character variables. Character variables can store only one letter e.g. A or B or C etc. printf(“%c”, ‘t’);

Displaying Variable Value %d These are called Format Specifiers used to display the value stored in the variable i.e. Inside computer memory.

Assignment Statements Before using variables in assignment statements you should define / declare them first e.g. int x; Assignment Statements x = 35; y = 21; sum = x + y; The first two statements assigns the values 35 and 21 to the variables x and y respectively The next statement assigns the sum of the two values to the variable sum.

Input Statement Scanf() Scanf is an input statement which is used to store values in different memory locations using variables For example: int X; scanf(“%d ”, &X); format specifier to display Integer values Address of Symbol If X string (No ‘&’ symbol on this one!)

Multiple Variables in one Scanf scanf(“%d %d”, &num1, &num2); It means that it would stop here and wait for the user to type in two values. Once they have been typed in & the Enter Key pressed, the values are assigned to num1 & num2.

Combining input & output Statements printf(“Input Two Integer Values ”); scanf(“%d %d”, &num1, &num2); In the first place, there is a problem that how the user would come to know about the program is waiting for two values? The program should prompt user to enter two values. Now it will be easy for user to understand which type of values he suppose to enter.

Things to Remember Make sure that the specifications agree with the data to be read. Make sure to put the & character before the variable name so that you specify the address of the variable in memory not the variable itself. The prompt message should be short and clear.

KIC/Introduction to Computer Programming 11/20/2019 KIC/Introduction to Computer Programming