19

Elements of c program....by thanveer danish

Embed Size (px)

DESCRIPTION

learn with hap

Citation preview

Page 1: Elements of c program....by thanveer danish
Page 2: Elements of c program....by thanveer danish

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Page 3: Elements of c program....by thanveer danish

Elements of programming

MUHAMMED [email protected]/usernametwitter.com/usernamein.linkedin.com/in/profilename9526960445

Page 4: Elements of c program....by thanveer danish

IN C LANGUAGE IMPORTENT THREE ELEMENTS

Page 5: Elements of c program....by thanveer danish

A variable is nothing but a name given to a storage area that our programs can manipulate.Type DescriptionChar Typically a single octet(one byte). Int The most natural size of integer for the machine.Float A single-precision floating point value.Double A double-precision floating point value.Void Represents the absence of type.Exampleint i, j, k; char c, ch; float f, salary; double d;

Variables

Page 6: Elements of c program....by thanveer danish

ConditionControlling flow of execution

Page 7: Elements of c program....by thanveer danish

if Statemento powerful decision making statement

o a two-way decision statementSyntax

if (conditional) { block of statements executed if conditional is true;}else{block of statements if condition false;}

Example

main(){int x=5if (x > 1){x=x+10; }printf("%d", x);}

Page 8: Elements of c program....by thanveer danish

if…else statementoExtension of the simple if statement

if (condition){True-block statement(s)}else{False-block statement(s)}

Syntax

Page 9: Elements of c program....by thanveer danish

if-else-if statement

EXAMPLE

void main(void) { int numb;   printf("Type any Number : ");  scanf("%d", &numb); if(numb > 0) {    printf("%d is the positive number", numb); }else if(numb < 0)    printf("%d is the Negative number", numb);else printf("%d is zero",numb);  }

Page 10: Elements of c program....by thanveer danish

Switch StatementThe switch and case statements help control complex conditional and branching operations.

Syntax:

switch (expression) {case item: statements; break;case item: statements; break;case item: statements; break;default: statement; break;}

Page 11: Elements of c program....by thanveer danish

Example:

#include main(){ int numb;printf("Type any Number");scanf("%d",&numb); switch(numb %2) { case 0 : printf("the number %d is even ", numb); case 1 : printf("the number %d is odd ", numb); break; }

}

Page 12: Elements of c program....by thanveer danish

Ternary conditionThe ? (ternary condition) operator is a more efficient form for expressing simple if statements. It has the following form:expression1 ? expression2: expression3

Example:res = (a>b) ? a : b;if a is greater than b than res has the value a else the res has value b.

Page 13: Elements of c program....by thanveer danish

obreak statementbreak statement is used to exit from a loop or a switch, control passing to the first statement beyond the loop or a switch.

for(i=0;i<=10;i++){ if(i==5) { break; } printf(" %d",i);}

Page 14: Elements of c program....by thanveer danish

ocontinue statement continue statement is a jump statement. it can be used only inside for loop, while loop and do-while loop

Example

for(i=0;i<10;i++){ if(i==5){continue;}printf(" %d",i);}

Page 15: Elements of c program....by thanveer danish

The goto statementThe goto is a unconditional branching statement used to transfer control of the program from one statement to another.

Syntax

goto label; ............. ............. ............. label: statement;

Page 16: Elements of c program....by thanveer danish

EXAMPLE#include <stdio.h> int main () { /* local variable definition */ int a = 10; /* do loop execution */ LOOP:do { if( a == 15) { /* skip the iteration */ a = a + 1; goto LOOP; } printf("value of a: %d\n", a); a++; }while( a < 20 ); return 0; }

answervalue of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19

Page 17: Elements of c program....by thanveer danish

LoopA loop statement allows us to execute a statement or group of statements multiple times

Page 18: Elements of c program....by thanveer danish

If this presentation helped you, please visit our page facebook.com/baabtra and like it.

Thanks in advance.

www.baabtra.com | www.massbaab.com |www.baabte.com

Page 19: Elements of c program....by thanveer danish

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: [email protected]