SlideShare une entreprise Scribd logo
1  sur  30
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
C programming decision making
C programming decision makingC programming decision making
C programming decision makingSENA
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow ChartRahul Sahu
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C pptMANJUTRIPATHI7
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail 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 javaSamsil Arefin
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal 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 programmingPriyansh Thakar
 

Tendances (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
 

Similaire à Programming basics

Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana 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 8Shipra Swati
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 
computer programming Control Statements.pptx
computer programming Control Statements.pptxcomputer programming Control Statements.pptx
computer programming Control Statements.pptxeaglesniper008
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptganeshkarthy
 
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.docxJavvajiVenkat
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin cVikash Dhal
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.comGreen Ecosystem
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptxPrecise Mya
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)jakejakejake2
 

Similaire à 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
 
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
 
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
 
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
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptx
 
Fundamentals of programming)
Fundamentals of programming)Fundamentals of programming)
Fundamentals of programming)
 

Dernier

JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
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
 

Dernier (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
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...
 

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