SlideShare a Scribd company logo
Programming Basics
Version_Sep_2013
C
SharpC
ode.org
Program..
Sequence of instructions written for specific purpose
Like program to find out factorial of number
Can be written in higher level programming languages that
human can understandhuman can understand
Those programs are translated to computer understandable
languages
Task will be done by special tool called compiler
Version_Sep_2013
C
SharpC
ode.org
Compiler will convert higher level language code to lower
language code like binary code
Most prior programming language was ‘C’
Rules & format that should be followed while writingRules & format that should be followed while writing
program are called syntax
Consider program to print “Hello!” on screen
Version_Sep_2013
C
SharpC
ode.org
void main()
{
printf(“Hello!”);
}}
Void main(), function and entry point of compilation
Part within two curly brackets, is body of function
Printf(), function to print sequence of characters on screen
Version_Sep_2013
C
SharpC
ode.org
Any programming language having three part
1. Data types
2. Keywords
3. Operators3. Operators
Data types are like int, float, double
Keyword are like printf, main, if, else
The words that are pre-defined for compiler are keyword
Keywords can not be used to define variable
Version_Sep_2013
C
SharpC
ode.org
We can define variable of data type
Like int a; then ‘a’ will hold value of type int and is called
variable
Programs can have different type of statements likePrograms can have different type of statements like
conditional statements and looping statements
Conditional statements are for checking some condition
Version_Sep_2013
C
SharpC
ode.org
Conditional Statements…
Conditional statements controls the sequence of
statements, depending on the condition
Relational operators allow comparing two values.
1. == is equal to1. == is equal to
2. != not equal to
3. < less than
4. > greater than
5. <= less than or equal to
6. >= greater than or equal to
Version_Sep_2013
C
SharpC
ode.org
SIMPLE IF STATEMENT
It execute if condition is TRUE
Syntax:
if(condition)
{{
Statement1;
.....
Statement n;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
int a,b;
printf(“Enter a,b values:”);
scanf(“%d %d”,&a,&b);
if(a>b) {
printf(“n a is greater than b”); }printf(“n a is greater than b”); }
}
OUTPUT:
Enter a,b values:20 10
a is greater than b
Version_Sep_2013
C
SharpC
ode.org
IF-ELSE STATEMENT
It execute IF condition is TRUE.IF condition is FLASE it execute ELSE part
Syntax:
if(condition)
{
Statement1;Statement1;
.....
Statement n;
}
else
{
Statement1;
.....
Statement n;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
int a,b;
printf(“Enter a,b values:”);
scanf(“%d %d”,&a,&b);
if(a>b) {
printf(“n a is greater than b”); }
else {else {
printf(“nb is greater than b”); }
}
OUTPUT:
Enter a,b values:10 20
b is greater than a
Version_Sep_2013
C
SharpC
ode.org
IF-ELSE IF STATEMENT:
It execute IF condition is TRUE.IF condition is FLASE it checks ELSE IF part
.ELSE IF is true then execute ELSE IF PART. This is also false it goes to ELSE
part.
Syntax:
if(condition)
{
Statementn;Statementn;
}
else if(condition)
{
Statementn;
}
else
{
Statement n;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
int a,b;
printf(“Enter a,b values:”);
scanf(“%d %d”,&a,&b);
if(a>b) {
printf(“n a is greater than b”); }
else if(b>a) {else if(b>a) {
printf(“nb is greater than b”); }
else {
printf(“n a is equal to b”); }
}
OUTPUT:
Enter a,b values:10 10
a is equal to b
Version_Sep_2013
C
SharpC
ode.org
NESTED IF STATEMENT
To check one conditoin within another.
Take care of brace brackets within the conditions.
Synatax:
if(condition)
{{
if(condition)
{
Statement n;
}
}
else
{
Statement n;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
int a,b;
printf(“n Enter a and b values:”);
scanf(“%d %d ”,&a,&b);
if(a>b) {
if((a!=0) && (b!=0)) {
printf(“na and b both are +ve and a >b); }
else {else {
printf(“n a is greater than b only”) ; } }
else {
printf(“ na is less than b”); }
}
Output:
Enter a and b values:30 20
a and b both are +ve and a > b
Version_Sep_2013
C
SharpC
ode.org
Switch..case
The switch statement is much like a nested if .. else statement.
switch statement can be slightly more efficient and easier to read.
Syntax :
switch( expression )
{
case constant-expression1:case constant-expression1:
statements1; break;
case constant-expression2:
statements2; break
default :
statements4; break;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
char Grade = ‘B’;
switch( Grade )
{
case 'A' :
printf( "Excellentn" ); break;
case 'B' :
printf( "Goodn" ); break;
case 'C' :case 'C' :
printf( "OKn" ); break;
case 'D' :
printf( "Mmmmm....n" ); break;
default :
printf( "What is your grade anyway?" );
break;
}
}
Version_Sep_2013
C
SharpC
ode.org
Looping…
Loops provide a way to repeat commands and control how many
times they are repeated.
C provides a number of looping way.
while loopwhile loop
A while statement is like a repeating if statement.
Like an If statement, if the test condition is true: the statements
get executed.
The difference is that after the statements have been executed,
the test condition is checked again.
If it is still true the statements get executed again.
This cycle repeats until the test condition evaluates to false.
Version_Sep_2013
C
SharpC
ode.org
Basic syntax of while loop is as follows:
while ( expression )
{
Single statement or Block of statements;Single statement or Block of statements;
}
Will check for expression, until its true when it gets false
execution will be stop
Version_Sep_2013
C
SharpC
ode.org
main()
{
int i = 5;
while ( i > 0 ) {
printf("Hello %dn", i );
i = i -1; }
}}
Output
Hello 5
Hello 4
Hello 3
Hello 2
Hello 1
Version_Sep_2013
C
SharpC
ode.org
Do..While
do ... while is just like a while loop except that the test
condition is checked at the end of the loop rather than the
start.
This has the effect that the content of the loop are alwaysThis has the effect that the content of the loop are always
executed at least once.
Basic syntax of do...while loop is as follows:
do {
Single statement or Block of statements; }
while(expression);
Version_Sep_2013
C
SharpC
ode.org
main()
{
int i = 5;
do{
printf("Hello %dn", i );
i = i -1; }
while ( i > 0 );
}}
Output
Hello 5
Hello 4
Hello 3
Hello 2
Hello 1
Version_Sep_2013
C
SharpC
ode.org
For Loop…
for loop is similar to while, it's just written differently. for
statements are often used to proccess lists such a range of
numbers:
Basic syntax of for loop is as follows:Basic syntax of for loop is as follows:
for( initialization; condition; increment)
{ Single statement or Block of statements;
}
Version_Sep_2013
C
SharpC
ode.org
main()
{
int i; int j = 5;
for( i = 0; i <= j; i ++ )
{
printf("Hello %dn", i );
}
}}
Output
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Version_Sep_2013
C
SharpC
ode.org
Break & Continue…
C provides two commands to control how we loop:
break -- exit form loop or switch.
continue -- skip 1 iteration of loop.
Break is used with switch caseBreak is used with switch case
Version_Sep_2013
C
SharpC
ode.org
main()
{
int i; int j = 5;
for( i = 0; i <= j; i ++ ) {
if( i == 3 )
{
break;
}}
printf("Hello %dn", i ); }
}
Output
Hello 0
Hello 1
Hello 2
Version_Sep_2013
C
SharpC
ode.org
Continue Example..
main()
{
int i; int j = 5;
for( i = 0; i <= j; i ++ )
{
if( i == 3 )
{{
continue;
}
printf("Hello %dn", i );
}
}
Output
Hello 0
Hello 1
Hello 2
Hello 4
Hello 5 Version_Sep_2013
C
SharpC
ode.org
Functions…
A function is a module or block of program code which
deals with a particular task.
Making functions is a way of isolating one block of code
from other independent blocks of code.from other independent blocks of code.
Functions serve two purposes.
1. They allow a programmer to say: `this piece of code does a
specific job which stands by itself and should not be mixed
up with anything else',
2. Second they make a block of code reusable since a function
can be reused in many different contexts without repeating
parts of the program text.
Version_Sep_2013
C
SharpC
ode.org
int add( int p1, int p2 ); //function declaration
void main()
{
int a = 10;
int b = 20, c;
c = add(a,b); //call to function
printf(“Addition is : %d”, c);printf(“Addition is : %d”, c);
}
int add( int p1, int p2 ) //function definition
{
return (p1+p2);
}
Version_Sep_2013
C
SharpC
ode.org
Exercise…
1. Find out factorial of given number
2. Check whether given number is prime number or not
3. Check whether given number is Armstrong number or
notnot
4. Calculate some of first 100 even numbers
5. Prepare calculator using switch
Version_Sep_2013
C
SharpC
ode.org

More Related Content

What's hot

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
SENA
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Control structure
Control structureControl structure
Control structure
Samsil Arefin
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Hossain Md Shakhawat
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
Zohaib Ahmed
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow Chart
Rahul Sahu
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
Samsil Arefin
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
Priyansh Thakar
 

What's hot (20)

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Control structure
Control structureControl structure
Control structure
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
For Loop
For LoopFor Loop
For Loop
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow Chart
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Bsit1
Bsit1Bsit1
Bsit1
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 

Similar to Programming basics

What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
Programming in C
Programming in CProgramming in C
Programming in C
Nishant Munjal
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
Tanmay Modi
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
eaglesniper008
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
ganeshkarthy
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinarurumedina
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
JavvajiVenkat
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
Chandrakant Divate
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
Vikash Dhal
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
Green Ecosystem
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
Rakesh Roshan
 

Similar to Programming basics (20)

What is c
What is cWhat is c
What is c
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptx
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
 
C Control Statements.docx
C Control Statements.docxC Control Statements.docx
C Control Statements.docx
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Lec 10
Lec 10Lec 10
Lec 10
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 

Programming basics

  • 2. Program.. Sequence of instructions written for specific purpose Like program to find out factorial of number Can be written in higher level programming languages that human can understandhuman can understand Those programs are translated to computer understandable languages Task will be done by special tool called compiler Version_Sep_2013 C SharpC ode.org
  • 3. Compiler will convert higher level language code to lower language code like binary code Most prior programming language was ‘C’ Rules & format that should be followed while writingRules & format that should be followed while writing program are called syntax Consider program to print “Hello!” on screen Version_Sep_2013 C SharpC ode.org
  • 4. void main() { printf(“Hello!”); }} Void main(), function and entry point of compilation Part within two curly brackets, is body of function Printf(), function to print sequence of characters on screen Version_Sep_2013 C SharpC ode.org
  • 5. Any programming language having three part 1. Data types 2. Keywords 3. Operators3. Operators Data types are like int, float, double Keyword are like printf, main, if, else The words that are pre-defined for compiler are keyword Keywords can not be used to define variable Version_Sep_2013 C SharpC ode.org
  • 6. We can define variable of data type Like int a; then ‘a’ will hold value of type int and is called variable Programs can have different type of statements likePrograms can have different type of statements like conditional statements and looping statements Conditional statements are for checking some condition Version_Sep_2013 C SharpC ode.org
  • 7. Conditional Statements… Conditional statements controls the sequence of statements, depending on the condition Relational operators allow comparing two values. 1. == is equal to1. == is equal to 2. != not equal to 3. < less than 4. > greater than 5. <= less than or equal to 6. >= greater than or equal to Version_Sep_2013 C SharpC ode.org
  • 8. SIMPLE IF STATEMENT It execute if condition is TRUE Syntax: if(condition) {{ Statement1; ..... Statement n; } Version_Sep_2013 C SharpC ode.org
  • 9. main() { int a,b; printf(“Enter a,b values:”); scanf(“%d %d”,&a,&b); if(a>b) { printf(“n a is greater than b”); }printf(“n a is greater than b”); } } OUTPUT: Enter a,b values:20 10 a is greater than b Version_Sep_2013 C SharpC ode.org
  • 10. IF-ELSE STATEMENT It execute IF condition is TRUE.IF condition is FLASE it execute ELSE part Syntax: if(condition) { Statement1;Statement1; ..... Statement n; } else { Statement1; ..... Statement n; } Version_Sep_2013 C SharpC ode.org
  • 11. main() { int a,b; printf(“Enter a,b values:”); scanf(“%d %d”,&a,&b); if(a>b) { printf(“n a is greater than b”); } else {else { printf(“nb is greater than b”); } } OUTPUT: Enter a,b values:10 20 b is greater than a Version_Sep_2013 C SharpC ode.org
  • 12. IF-ELSE IF STATEMENT: It execute IF condition is TRUE.IF condition is FLASE it checks ELSE IF part .ELSE IF is true then execute ELSE IF PART. This is also false it goes to ELSE part. Syntax: if(condition) { Statementn;Statementn; } else if(condition) { Statementn; } else { Statement n; } Version_Sep_2013 C SharpC ode.org
  • 13. main() { int a,b; printf(“Enter a,b values:”); scanf(“%d %d”,&a,&b); if(a>b) { printf(“n a is greater than b”); } else if(b>a) {else if(b>a) { printf(“nb is greater than b”); } else { printf(“n a is equal to b”); } } OUTPUT: Enter a,b values:10 10 a is equal to b Version_Sep_2013 C SharpC ode.org
  • 14. NESTED IF STATEMENT To check one conditoin within another. Take care of brace brackets within the conditions. Synatax: if(condition) {{ if(condition) { Statement n; } } else { Statement n; } Version_Sep_2013 C SharpC ode.org
  • 15. main() { int a,b; printf(“n Enter a and b values:”); scanf(“%d %d ”,&a,&b); if(a>b) { if((a!=0) && (b!=0)) { printf(“na and b both are +ve and a >b); } else {else { printf(“n a is greater than b only”) ; } } else { printf(“ na is less than b”); } } Output: Enter a and b values:30 20 a and b both are +ve and a > b Version_Sep_2013 C SharpC ode.org
  • 16. Switch..case The switch statement is much like a nested if .. else statement. switch statement can be slightly more efficient and easier to read. Syntax : switch( expression ) { case constant-expression1:case constant-expression1: statements1; break; case constant-expression2: statements2; break default : statements4; break; } Version_Sep_2013 C SharpC ode.org
  • 17. main() { char Grade = ‘B’; switch( Grade ) { case 'A' : printf( "Excellentn" ); break; case 'B' : printf( "Goodn" ); break; case 'C' :case 'C' : printf( "OKn" ); break; case 'D' : printf( "Mmmmm....n" ); break; default : printf( "What is your grade anyway?" ); break; } } Version_Sep_2013 C SharpC ode.org
  • 18. Looping… Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way. while loopwhile loop A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statements get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again. This cycle repeats until the test condition evaluates to false. Version_Sep_2013 C SharpC ode.org
  • 19. Basic syntax of while loop is as follows: while ( expression ) { Single statement or Block of statements;Single statement or Block of statements; } Will check for expression, until its true when it gets false execution will be stop Version_Sep_2013 C SharpC ode.org
  • 20. main() { int i = 5; while ( i > 0 ) { printf("Hello %dn", i ); i = i -1; } }} Output Hello 5 Hello 4 Hello 3 Hello 2 Hello 1 Version_Sep_2013 C SharpC ode.org
  • 21. Do..While do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are alwaysThis has the effect that the content of the loop are always executed at least once. Basic syntax of do...while loop is as follows: do { Single statement or Block of statements; } while(expression); Version_Sep_2013 C SharpC ode.org
  • 22. main() { int i = 5; do{ printf("Hello %dn", i ); i = i -1; } while ( i > 0 ); }} Output Hello 5 Hello 4 Hello 3 Hello 2 Hello 1 Version_Sep_2013 C SharpC ode.org
  • 23. For Loop… for loop is similar to while, it's just written differently. for statements are often used to proccess lists such a range of numbers: Basic syntax of for loop is as follows:Basic syntax of for loop is as follows: for( initialization; condition; increment) { Single statement or Block of statements; } Version_Sep_2013 C SharpC ode.org
  • 24. main() { int i; int j = 5; for( i = 0; i <= j; i ++ ) { printf("Hello %dn", i ); } }} Output Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Version_Sep_2013 C SharpC ode.org
  • 25. Break & Continue… C provides two commands to control how we loop: break -- exit form loop or switch. continue -- skip 1 iteration of loop. Break is used with switch caseBreak is used with switch case Version_Sep_2013 C SharpC ode.org
  • 26. main() { int i; int j = 5; for( i = 0; i <= j; i ++ ) { if( i == 3 ) { break; }} printf("Hello %dn", i ); } } Output Hello 0 Hello 1 Hello 2 Version_Sep_2013 C SharpC ode.org
  • 27. Continue Example.. main() { int i; int j = 5; for( i = 0; i <= j; i ++ ) { if( i == 3 ) {{ continue; } printf("Hello %dn", i ); } } Output Hello 0 Hello 1 Hello 2 Hello 4 Hello 5 Version_Sep_2013 C SharpC ode.org
  • 28. Functions… A function is a module or block of program code which deals with a particular task. Making functions is a way of isolating one block of code from other independent blocks of code.from other independent blocks of code. Functions serve two purposes. 1. They allow a programmer to say: `this piece of code does a specific job which stands by itself and should not be mixed up with anything else', 2. Second they make a block of code reusable since a function can be reused in many different contexts without repeating parts of the program text. Version_Sep_2013 C SharpC ode.org
  • 29. int add( int p1, int p2 ); //function declaration void main() { int a = 10; int b = 20, c; c = add(a,b); //call to function printf(“Addition is : %d”, c);printf(“Addition is : %d”, c); } int add( int p1, int p2 ) //function definition { return (p1+p2); } Version_Sep_2013 C SharpC ode.org
  • 30. Exercise… 1. Find out factorial of given number 2. Check whether given number is prime number or not 3. Check whether given number is Armstrong number or notnot 4. Calculate some of first 100 even numbers 5. Prepare calculator using switch Version_Sep_2013 C SharpC ode.org