SlideShare a Scribd company logo
1 of 64
CSEG1001 Computer Programming
CSEG 1001
Computer Programming
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
Road Map
• Generations of Computers and Languages
• Organization of Computers-Online Lecture
• Number Systems Conversion
• Logical Analysis and Thinking
Introduction to
Computers
• Structure of C Program & Compilation and Linking Process
• Variables and Datatypes
• Managing Input and Output statements and Operators
• Decision and Looping Statements
C Programming
Basics
• Creation and Usages
• 1D and 2 D arrys
• String Functions
• Matrix operations
Arrays and
Strings
• Declaration and Definitions of Functions
• Passing Arguments
• Recursion
• Pointers & Pointer Arithmetic
Functions and
Pointers
• Need of Structure and Unions
• Declaration and Definition
• Storage classes
• Preprocessor Directives
Structures and
Unions
CSEG1001 Computer Programming
LECTURE #8
STRUCTURE OF C PROGRAM ..COMPILATIONAND
LINKING
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
Steps in C compilation
• Compiling a C program is a multi-stage process
• It contains four separate stages:
• Traditional C compilers orchestrate this process by
invoking other programs to handle each stage.
CSEG1001 Computer Programming
Preprocessing Compilation Assembly Linking
CSEG1001 Computer Programming
Compiling and Executing C Program
CSEG1001 Computer Programming
Files in a C program
CSEG1001 Computer Programming
Structure
of
C
Program
CSEG1001 Computer Programming
Documentation
• Comments
• provide clarity to the C source code
• allows others to better understand
• helps in debugging the code.
• Two types
• Single Line //
• Multiline /* any text */
CSEG1001 Computer Programming
Hello World in C
// This is my first Program
/* Written for Engineering students of
Petroleum University */
#include <stdio.h>
void main()
{
printf(“Hello”);
}
11
Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
Preprocessing
• First stage of compilation
• Lines starting with a # character are interpreted by the
preprocessor as preprocessor commands.
• This language is used to reduce repetition in source code
• Print the result of the preprocessing stage, pass the -E
option to cc:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
CSEG1001 Computer Programming
Function / Block
• Definition: Function/Procedure/Sub-routine
• Set of Instructions that are executed to achieve a particular task
• Code reusability
• Types
• Built-in Functions (System Defined)
• E.g. printf(), scanf()
• User-defined Functions
13
Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
Main() function
 main() is always the first function called in a program
execution.
void main( void ) or int main()
{ … {….
 void indicates that the function takes no arguments
 int indicates that the function returns an integer value
CSEG1001 Computer Programming
LECTURE #9
VARIABLESAND DATATYPES
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
Data & Variable
CSEG1001 Computer Programming
DataType in C language
CSEG1001 Computer Programming
18
Variables
• Naming a Variable
• Must be a valid identifier.
• Must not be a keyword
• Names are case sensitive.
• Variables are identified by only first 32 characters.
• length
• lowerLimit lower_limit
• incomeTax income_tax
Variable Declaration / Definition
• Declaring/Definition a Variable
• Declaration announces the data type of a variable and allocates
appropriate memory location.
• Each variable used must be declared.
• A form of a declaration statement is
data-type var1, var2,…;
Examples
int sum = 0;
char t1 = ‘a’;
float epsilon = 1.44;
Variable Definition and Initialization
If not initialized it will take a garbage value.
CSEG1001 Computer Programming
22
Global and Local Variables
• Global Variables
• These variables are
declared outside all
functions.
• Life time of a global
variable is the entire
execution period of the
program.
• Can be accessed by any
function defined below the
declaration, in a file.
• Local Variables
• These variables are
declared inside some
functions.
• Life time of a local
variable is the entire
execution period of the
function in which it is
defined.
• Cannot be accessed by any
other function.
• In general variables
declared inside a block are
accessible only in that
block.
Example
23
Constants
• The value will not change wherever declared
• Declared using const keyword
• Eg.
const float pi=3.14;
CSEG1001 Computer Programming
LECTURE #10
INPUTAND OUTPUT STATEMENTS
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
OUTPUT STATEMENT - printf()
• printf() function
• Output to Standard Output
• Prototype definition available in stdio.h
26
Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
• Case 1: printing only text
Flowchart code Output
printf(“Hello”); Hello
• Case 2: printing only value of a variable
printf(“%d” , area); 120
• Case 3: printing text and a value
printf(“The value of area is %d”,area); The value of area is 120
Print Hello
Print area
OUTPUT STATEMENT - printf()
INPUT STATEMENT – scanf()
• Case 1: getting 1 input value
scanf( “%d”, &r);
• Case 2: getting 2 input value
scanf( “%d %d ”, &l, &b);
• Case 3: getting 3 input value
scanf( “%d %d %d ”, &a, &b ,&c);
• scanf() function
• Input from Standard Input
• Prototype definition available in stdio.h
• Format Specifier(%d)
• Address-of Operator (&)
• Provides the memory address of the input variable were the input value is to
be stored
29
Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
Format Specifiers in C
• Used in association with printf() and scanf()
CSEG1001 Computer Programming
ONLINE LECTURE #11
OPERATORS IN C
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
Online lectures
CSEG1001 Computer Programming
CSEG1001 Computer Programming
CSEG1001 Computer Programming
Ternary Operator - Conditional Check
Operator
CSEG1001 Computer Programming
Example
CSEG1001 Computer Programming
LECTURE #12
DECISION STRUCTURES IN C
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
List of Decision Making Structures in C
•If structure
•If Else structure
•Nested If structure
•Switch Structures
•Conditional Operator/
Terniary operator
CSEG1001 Computer Programming
Converting a if block to C program
CSEG1001 Computer Programming
if(condition)
{
//true statements
}
Check if entered number is positive
CSEG1001 Computer Programming
Converting a if-else block to C program
CSEG1001 Computer Programming
if(condition)
{
//true statements
}
else
{
//false statements
}
Example: If Else Statement
CSEG1001 Computer Programming
Nested IF
CSEG1001 Computer Programming
if(condition 1)
{
//true statements
}
else if(condition 2)
{
//statements
}
else if(condition 3)
{
//statements
}
else
{
//statements
}
Example
CSEG1001 Computer Programming
Switch case Vs Nested IF
CSEG1001 Computer Programming
Convert Switch to C program
CSEG1001 Computer Programming
Knowledge Checks
#include <stdio.h>
void solveMeFirst( )
{
int num1,num2;
scanf("%d %d",&num1,&num2);
int sum;
sum = num1+num2;
printf("%d",sum);
}
void main()
{
________________Fill me
}
CSEG1001 Computer Programming
Knowledge Checks
CSEG1001 Computer Programming
EXPERIMENT NO – 4
Control Statements in C Language
List of lab works:
1. Write a program to accept 3 numbers and find the greatest of them, using
if…….else statements.
2. Write a program to find the biggest of 3 numbers using conditional operator/ternary
operator?
3. Write a program to check whether the roots of a quadratic equation are real or
imaginary?
4. Program to find the average of students marks, if average<50 then result is ‘FAIL’
otherwise print the grade as pass /first class/distinction.
5. A book and stationary store decides to give its customers 10% discount on a
purchase greater than 10,000/-. The program should accept the quantity
purchased the price of the items and then calculate the amount payable. Further
based on the total amount, appropriate discount should be given and final payable
amount should be displayed.
6. Write a program to accept a number and display “Sunday/Monday/Tuesday…..”
Based on the number. (hint: if 1 is input then “Sunday”, if 2 is input then
“Monday”…..) using switch case.
7. Read the minutes from the keyboard and find out the no. of hours, mins , days ?
(Ex 1210 mins are displayed as 0 days,20 hrs,10 min)
CSEG1001 Computer Programming
LECTURE #13
LOOP STRUCTURES IN C
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1001 Computer Programming
Introduction - Loop Statements
• Helps in executing a statement in flowchart repeatedly
• Loop statements – block of statement executed more
than one time
• How many times the loop statements are executed is
managed by a counter variable
• Counter Variable Initialization
• Eg. C=0
• Counter Variable Increment/Decrement
• Eg. C++, c=c+1,c=c+3
• Counter Variable Condition Check
• Eg. C<3
CSEG1001 Computer Programming
List of Loop Structures in C
• While
• Do….While
• For
CSEG1001 Computer Programming
While
• Entry condition check loop
CSEG1001 Computer Programming
CSEG1001 Computer Programming
Example – While Program
CSEG1001 Computer Programming
Do … While Loop
• Exit check Loop
• At least executes the
statement once
if the condition is false
CSEG1001 Computer Programming
At least executes once - if condition fails
CSEG1001 Computer Programming
CSEG1001 Computer Programming
For
CSEG1001 Computer Programming
Example
CSEG1001 Computer Programming
CSEG1001 Computer Programming
Continue statement
CSEG1001 Computer Programming
EXPERIMENT NO – 5
Loop Statements in C Language
List of lab works:
1. Write a program to print half pyramid using *.
2. Write a C program to print all natural numbers from 1-n
using while loop.
3. Write a C program to find the sum of all even numbers
between 1 to n using do-while loop.
4. Write a C program to print multiplication table of any
number using for loop.
CSEG1001 Computer Programming
CSEG1001 Computer Programming

More Related Content

What's hot

Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)Umair Younas
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)Dr. Ahmed Al Zaidy
 
CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)Dr. Ahmed Al Zaidy
 
Chapter 1 - An Overview of Computers and Programming Languages
Chapter 1 - An Overview of Computers and Programming LanguagesChapter 1 - An Overview of Computers and Programming Languages
Chapter 1 - An Overview of Computers and Programming LanguagesAdan Hubahib
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life CycleFrankie Jones
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge imtiazalijoono
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1deathful
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2deathful
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)Dr. Ahmed Al Zaidy
 

What's hot (20)

Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
Lesson 1 introduction to programming
Lesson 1 introduction to programmingLesson 1 introduction to programming
Lesson 1 introduction to programming
 
Problem solving (C++ Programming)
Problem solving (C++ Programming)Problem solving (C++ Programming)
Problem solving (C++ Programming)
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
CIS110 Computer Programming Design Chapter (5)
CIS110 Computer Programming Design Chapter  (5)CIS110 Computer Programming Design Chapter  (5)
CIS110 Computer Programming Design Chapter (5)
 
CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)
 
Chapter 1 - An Overview of Computers and Programming Languages
Chapter 1 - An Overview of Computers and Programming LanguagesChapter 1 - An Overview of Computers and Programming Languages
Chapter 1 - An Overview of Computers and Programming Languages
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
C basics
C basicsC basics
C basics
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
Logic Formulation 1
Logic Formulation 1Logic Formulation 1
Logic Formulation 1
 
L1
L1L1
L1
 
Graphical programming
Graphical programmingGraphical programming
Graphical programming
 
Chapter 02 - Problem Solving
Chapter 02 - Problem SolvingChapter 02 - Problem Solving
Chapter 02 - Problem Solving
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
 

Similar to CSEG1001Unit 2 C Programming Fundamentals

Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 EstimationLawrence Bernstein
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Dhiviya Rose
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of Ceducationfront
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and typesimtiazalijoono
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfmadihamaqbool6
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSDr.YNM
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfMMRF2
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdfAhmedEmadElGhetany
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptxSanuSan3
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6Shah Zaib
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Mohamed El Desouki
 

Similar to CSEG1001Unit 2 C Programming Fundamentals (20)

Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 Estimation
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
Cse
CseCse
Cse
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Vedic Calculator
Vedic CalculatorVedic Calculator
Vedic Calculator
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
College1
College1College1
College1
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Technical trainning.pptx
Technical trainning.pptxTechnical trainning.pptx
Technical trainning.pptx
 
Parallel Computing - Lec 6
Parallel Computing - Lec 6Parallel Computing - Lec 6
Parallel Computing - Lec 6
 
Chapter 01.PPT
Chapter 01.PPTChapter 01.PPT
Chapter 01.PPT
 
Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++Basic Programming concepts - Programming with C++
Basic Programming concepts - Programming with C++
 

More from Dhiviya Rose

Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Dhiviya Rose
 
Module 3 microsoft powerpoint
Module 3 microsoft powerpointModule 3 microsoft powerpoint
Module 3 microsoft powerpointDhiviya Rose
 
Module 3 business computing.pdf
Module 3 business computing.pdfModule 3 business computing.pdf
Module 3 business computing.pdfDhiviya Rose
 
Module 2 Digital Devices and its Applications
Module 2 Digital Devices and its ApplicationsModule 2 Digital Devices and its Applications
Module 2 Digital Devices and its ApplicationsDhiviya Rose
 
Unit 1 Business Computing
Unit 1 Business ComputingUnit 1 Business Computing
Unit 1 Business ComputingDhiviya Rose
 
Module 1 - Digital Devices and its Application
Module 1 - Digital Devices and its ApplicationModule 1 - Digital Devices and its Application
Module 1 - Digital Devices and its ApplicationDhiviya Rose
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsDhiviya Rose
 
CSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersCSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersDhiviya Rose
 
CSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and UnionsCSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and UnionsDhiviya Rose
 
Lecture 3 internet and web
Lecture 3 internet and webLecture 3 internet and web
Lecture 3 internet and webDhiviya Rose
 
Multidimentional array
Multidimentional arrayMultidimentional array
Multidimentional arrayDhiviya Rose
 
Searching in Arrays
Searching in ArraysSearching in Arrays
Searching in ArraysDhiviya Rose
 

More from Dhiviya Rose (14)

Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1
 
Module 3 microsoft powerpoint
Module 3 microsoft powerpointModule 3 microsoft powerpoint
Module 3 microsoft powerpoint
 
Module 3 business computing.pdf
Module 3 business computing.pdfModule 3 business computing.pdf
Module 3 business computing.pdf
 
Module 2 Digital Devices and its Applications
Module 2 Digital Devices and its ApplicationsModule 2 Digital Devices and its Applications
Module 2 Digital Devices and its Applications
 
Software
SoftwareSoftware
Software
 
Unit 1 Business Computing
Unit 1 Business ComputingUnit 1 Business Computing
Unit 1 Business Computing
 
Module 1 - Digital Devices and its Application
Module 1 - Digital Devices and its ApplicationModule 1 - Digital Devices and its Application
Module 1 - Digital Devices and its Application
 
CSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and StringsCSEG1001Unit 3 Arrays and Strings
CSEG1001Unit 3 Arrays and Strings
 
CSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and PointersCSEG1001 Unit 4 Functions and Pointers
CSEG1001 Unit 4 Functions and Pointers
 
CSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and UnionsCSEG1001 Unit 5 Structure and Unions
CSEG1001 Unit 5 Structure and Unions
 
Lecture 3 internet and web
Lecture 3 internet and webLecture 3 internet and web
Lecture 3 internet and web
 
Strings
StringsStrings
Strings
 
Multidimentional array
Multidimentional arrayMultidimentional array
Multidimentional array
 
Searching in Arrays
Searching in ArraysSearching in Arrays
Searching in Arrays
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

CSEG1001Unit 2 C Programming Fundamentals

  • 2. CSEG 1001 Computer Programming Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 3. Road Map • Generations of Computers and Languages • Organization of Computers-Online Lecture • Number Systems Conversion • Logical Analysis and Thinking Introduction to Computers • Structure of C Program & Compilation and Linking Process • Variables and Datatypes • Managing Input and Output statements and Operators • Decision and Looping Statements C Programming Basics • Creation and Usages • 1D and 2 D arrys • String Functions • Matrix operations Arrays and Strings • Declaration and Definitions of Functions • Passing Arguments • Recursion • Pointers & Pointer Arithmetic Functions and Pointers • Need of Structure and Unions • Declaration and Definition • Storage classes • Preprocessor Directives Structures and Unions CSEG1001 Computer Programming
  • 4. LECTURE #8 STRUCTURE OF C PROGRAM ..COMPILATIONAND LINKING Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 5. Steps in C compilation • Compiling a C program is a multi-stage process • It contains four separate stages: • Traditional C compilers orchestrate this process by invoking other programs to handle each stage. CSEG1001 Computer Programming Preprocessing Compilation Assembly Linking
  • 7. Compiling and Executing C Program CSEG1001 Computer Programming
  • 8. Files in a C program CSEG1001 Computer Programming
  • 10. Documentation • Comments • provide clarity to the C source code • allows others to better understand • helps in debugging the code. • Two types • Single Line // • Multiline /* any text */ CSEG1001 Computer Programming
  • 11. Hello World in C // This is my first Program /* Written for Engineering students of Petroleum University */ #include <stdio.h> void main() { printf(“Hello”); } 11 Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
  • 12. Preprocessing • First stage of compilation • Lines starting with a # character are interpreted by the preprocessor as preprocessor commands. • This language is used to reduce repetition in source code • Print the result of the preprocessing stage, pass the -E option to cc: #include <stdio.h> #include <stdlib.h> #include <string.h> CSEG1001 Computer Programming
  • 13. Function / Block • Definition: Function/Procedure/Sub-routine • Set of Instructions that are executed to achieve a particular task • Code reusability • Types • Built-in Functions (System Defined) • E.g. printf(), scanf() • User-defined Functions 13 Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
  • 14. Main() function  main() is always the first function called in a program execution. void main( void ) or int main() { … {….  void indicates that the function takes no arguments  int indicates that the function returns an integer value CSEG1001 Computer Programming
  • 15. LECTURE #9 VARIABLESAND DATATYPES Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 16. Data & Variable CSEG1001 Computer Programming
  • 17. DataType in C language CSEG1001 Computer Programming
  • 18. 18
  • 19. Variables • Naming a Variable • Must be a valid identifier. • Must not be a keyword • Names are case sensitive. • Variables are identified by only first 32 characters. • length • lowerLimit lower_limit • incomeTax income_tax
  • 20. Variable Declaration / Definition • Declaring/Definition a Variable • Declaration announces the data type of a variable and allocates appropriate memory location. • Each variable used must be declared. • A form of a declaration statement is data-type var1, var2,…; Examples int sum = 0; char t1 = ‘a’; float epsilon = 1.44;
  • 21. Variable Definition and Initialization If not initialized it will take a garbage value. CSEG1001 Computer Programming
  • 22. 22 Global and Local Variables • Global Variables • These variables are declared outside all functions. • Life time of a global variable is the entire execution period of the program. • Can be accessed by any function defined below the declaration, in a file. • Local Variables • These variables are declared inside some functions. • Life time of a local variable is the entire execution period of the function in which it is defined. • Cannot be accessed by any other function. • In general variables declared inside a block are accessible only in that block.
  • 24. Constants • The value will not change wherever declared • Declared using const keyword • Eg. const float pi=3.14; CSEG1001 Computer Programming
  • 25. LECTURE #10 INPUTAND OUTPUT STATEMENTS Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 26. OUTPUT STATEMENT - printf() • printf() function • Output to Standard Output • Prototype definition available in stdio.h 26 Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
  • 27. • Case 1: printing only text Flowchart code Output printf(“Hello”); Hello • Case 2: printing only value of a variable printf(“%d” , area); 120 • Case 3: printing text and a value printf(“The value of area is %d”,area); The value of area is 120 Print Hello Print area OUTPUT STATEMENT - printf()
  • 28. INPUT STATEMENT – scanf() • Case 1: getting 1 input value scanf( “%d”, &r); • Case 2: getting 2 input value scanf( “%d %d ”, &l, &b); • Case 3: getting 3 input value scanf( “%d %d %d ”, &a, &b ,&c);
  • 29. • scanf() function • Input from Standard Input • Prototype definition available in stdio.h • Format Specifier(%d) • Address-of Operator (&) • Provides the memory address of the input variable were the input value is to be stored 29 Instructor: Dhiviya Rose J , AP-Sr. Scale | CIT
  • 30. Format Specifiers in C • Used in association with printf() and scanf() CSEG1001 Computer Programming
  • 31. ONLINE LECTURE #11 OPERATORS IN C Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 35. Ternary Operator - Conditional Check Operator CSEG1001 Computer Programming
  • 37. LECTURE #12 DECISION STRUCTURES IN C Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 38. List of Decision Making Structures in C •If structure •If Else structure •Nested If structure •Switch Structures •Conditional Operator/ Terniary operator CSEG1001 Computer Programming
  • 39. Converting a if block to C program CSEG1001 Computer Programming if(condition) { //true statements }
  • 40. Check if entered number is positive CSEG1001 Computer Programming
  • 41. Converting a if-else block to C program CSEG1001 Computer Programming if(condition) { //true statements } else { //false statements }
  • 42. Example: If Else Statement CSEG1001 Computer Programming
  • 43. Nested IF CSEG1001 Computer Programming if(condition 1) { //true statements } else if(condition 2) { //statements } else if(condition 3) { //statements } else { //statements }
  • 45. Switch case Vs Nested IF CSEG1001 Computer Programming
  • 46. Convert Switch to C program CSEG1001 Computer Programming
  • 47. Knowledge Checks #include <stdio.h> void solveMeFirst( ) { int num1,num2; scanf("%d %d",&num1,&num2); int sum; sum = num1+num2; printf("%d",sum); } void main() { ________________Fill me } CSEG1001 Computer Programming
  • 49. EXPERIMENT NO – 4 Control Statements in C Language List of lab works: 1. Write a program to accept 3 numbers and find the greatest of them, using if…….else statements. 2. Write a program to find the biggest of 3 numbers using conditional operator/ternary operator? 3. Write a program to check whether the roots of a quadratic equation are real or imaginary? 4. Program to find the average of students marks, if average<50 then result is ‘FAIL’ otherwise print the grade as pass /first class/distinction. 5. A book and stationary store decides to give its customers 10% discount on a purchase greater than 10,000/-. The program should accept the quantity purchased the price of the items and then calculate the amount payable. Further based on the total amount, appropriate discount should be given and final payable amount should be displayed. 6. Write a program to accept a number and display “Sunday/Monday/Tuesday…..” Based on the number. (hint: if 1 is input then “Sunday”, if 2 is input then “Monday”…..) using switch case. 7. Read the minutes from the keyboard and find out the no. of hours, mins , days ? (Ex 1210 mins are displayed as 0 days,20 hrs,10 min) CSEG1001 Computer Programming
  • 50. LECTURE #13 LOOP STRUCTURES IN C Instructor Dhiviya Rose J . Asst. Prof. Senior Scale School of Computer Science and Engineering | UPES CSEG1001 Computer Programming
  • 51. Introduction - Loop Statements • Helps in executing a statement in flowchart repeatedly • Loop statements – block of statement executed more than one time • How many times the loop statements are executed is managed by a counter variable • Counter Variable Initialization • Eg. C=0 • Counter Variable Increment/Decrement • Eg. C++, c=c+1,c=c+3 • Counter Variable Condition Check • Eg. C<3 CSEG1001 Computer Programming
  • 52. List of Loop Structures in C • While • Do….While • For CSEG1001 Computer Programming
  • 53. While • Entry condition check loop CSEG1001 Computer Programming
  • 55. Example – While Program CSEG1001 Computer Programming
  • 56. Do … While Loop • Exit check Loop • At least executes the statement once if the condition is false CSEG1001 Computer Programming
  • 57. At least executes once - if condition fails CSEG1001 Computer Programming
  • 63. EXPERIMENT NO – 5 Loop Statements in C Language List of lab works: 1. Write a program to print half pyramid using *. 2. Write a C program to print all natural numbers from 1-n using while loop. 3. Write a C program to find the sum of all even numbers between 1 to n using do-while loop. 4. Write a C program to print multiplication table of any number using for loop. CSEG1001 Computer Programming