Elements of c program....by thanveer danish
-
Upload
muhammed-thanveer-danish-melayi -
Category
Software
-
view
59 -
download
1
description
Transcript of 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
Elements of programming
MUHAMMED [email protected]/usernametwitter.com/usernamein.linkedin.com/in/profilename9526960445
IN C LANGUAGE IMPORTENT THREE ELEMENTS
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
ConditionControlling flow of execution
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);}
if…else statementoExtension of the simple if statement
if (condition){True-block statement(s)}else{False-block statement(s)}
Syntax
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); }
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;}
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; }
}
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.
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);}
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);}
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;
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
LoopA loop statement allows us to execute a statement or group of statements multiple times
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
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]