• No se han encontrado resultados

Cap´ıtulo 2

2.2.1. Descripci´ on al modelo de extinci´ on realizado

Comma Operator:

This operator is used to link the related expression together. A comma linked list of expressions are evaluated left to right and the value of rightmost expression is the value of the combined

expression. Ex:

Value=(x=10,y=5,x+y=0)

sizeof Operators:

This is a compile time operator and returns the sizeof bytes occupied by the operand.

Syntax:

Sizeof(var);

Control structures or statements ---

c is a considered as a structured programming language one of the reason for this is

having varios program control statements C process the decision making capabilities and supports

the statements known as control statements C supports three types of control statements they

are

1.Conditional control statements 2.Unconditional control statements 3.Loop control statements

(1) Conditional control statements:'C' supports five types of conditional control

statements.They are (a) Simple if (b)if-else (c)Nested if (d)else_if (e)switch Simple if statement : ...

It is the decision making statement and is used to control the flow of execution syntax : ... if(expression) { statements }

In the statement first the expression will be evaluated and control transfer to the next

Note: ...

In any control statement the statement block contain only a single statements {} brases are not

neccessary. Trassing --- F7 OR F8 Outside --- RED COLOR ctrl+f8 inside outside

(1)./* wap to find the maxium value of given two numbers using Simple if statement */ #include<stdio.h> #include<conio.h> void main() { int a,b,max; clrscr();

printf("Enter any two values:"); Scanf("%d%d",&a,&b);

max=a; if(max<b) {

}

printf("maxium value =%d",max); getch();

} output :

...

Enter any two values :10 20 max:20

(2)./* wap to find the maxium value of given three numbers using simple if statements */ #include<stdio.h> #include<conio.h> void main() { int a,b,c,max; clrscr();

printf("enter any three values:"); scanf("%d%d%d",&a,&b,&c); max=a; if(max<b) max=b; if(max<c) max=c;

printf("maxium value =%d ",max); getch();

}

OUTPUT ---

Enter any three values :10,20,30 Max =30. --- #include<stdio.h> #include<conio.h> void main() { int cd,cm,cy,bd,bm,by,d,m,y; clrscr();

Printf("Enter current Date (dd-mm-yy):"); scanf("%d%d%d%d",&cd&cm&cy);

printf("Enter Date of birth(dd-mm-yyyy):"); scanf("%d%d%d%d",&bd&bm&by); d=cd-bd; m=cm-bm; y=cy-by; if(d<0) { d=d+30; m--; } if(m<0) { m=m+12; y--; }

printf("age is %d years %d months and %d days",y,m,d); getch();

IF-ELSE STATEMENT: ---

It is an extension of simple if statement . syntax: --- if(expr) { statements-1; } else { statements-2; } ---i

if the expression is true then the if block statements are executed and else block statements are

ignored.otherwise expression is false then else block statement is executed and if block

statement is ignored.

/* wap to find the maxium value of given two numbers using if-else statement*/ #include<stdio.h>

#include<conio.h> void main

int a,b,max; clrscr():

printf("enter any two values:"); scanf("%d%d",&a&b);

if(a>b) max=a; else max=b;

printf("maximum value =%d",max"); getch();

}

--- Unconditional Control statements

Break:

It is a unconditional control statement and used to terminate a switch statement or loop statement .

Syntax: Break; Continue:

It is a unconditional control statement, it passes the control. Syntax:

Continue;

Causes control to pass to the end of the inter most enclosing while, do or for statement at which point the loop continuation is reevaluated.

Goto statement:

It is an unconditional control statement which is used to alter the execution of program sequence by transfer of control to the same other part of the program.

Syntax:

that the control could transferred to label. Syntax:

Label: Gotoxy:

It is a function, it moves the courser to the specified location in the current text window.

Syntax:

Void gotoxy(int x,int y); x- columns -> 80 y – rows -> 25. Note:

If the coordinates are invlid then gotoxy is ignored.

Loop control statements

The process of repeatedly executing a block of statements up to specify no. of times is called as “loop”.

Every loop has 3 parts

 Initialization --- start

 Test condition --- condition

 Change the index --- end

C supports 3 types of looping statements. They are 1) While loop

2) Do_while loop 3) For loop While loop:

It is a conditional control loop statement in c language. Syntax:

While(test condition) {

Statements; }

In this statements the first the text condition will be evaluated. It is true then the statement block will be executed. After the execution of statement block the text condition. If it is true then the statement block will be executed once again. This then process of repeated execution continues until the text condition finally becomes false.

Do – while Loop

It is an alternative form of the while loop. The only difference between while and do_while is the minimum no.of execution of while is zero, but the minimum no.of exectuin of do_while is one.

Syntax: Do {

}while(test condition);

In do while loop first the statement block will be executed and then test condition will be evaluated if it is true then the statement block will be executed once again. This process of repeated execution continuous until the test condition becomes false.

For Loop

It is the most commonly used loop statement in ‘c’ language. It si consisting of 3 expressions Syntax: For(exp1;exp2;exp3) { Statements; }

The first expression used to initialize the index. The second expression used to check whether the loop is continuation or not and.

Nested Loops:

Using a loop statement with in another loop is called as nested loop.

Text Window Formattings

Text Mode:

It changes screen mode. Declaration:

Void textmode(int newmode);

Text modes:-

Constant value TextMode

Lastmode -1 previous text mode 40 cols

BW40 0 black & white 40 cols

C40 1 color 40 cols

BW80 2 black & white 80 cols

C80 3 color 80 cols

MONO 7 Monochrome 43 lines

C4350 64 EGA AND VGA 50 lines

Eg: #include<stdio.h> #include<conio.h> Void main() { Clrscr(); Textmode(1);

Gotoxy(18,12); Printf(“WELCOME”): Getch();

}

_setcursortype:

It selects cursor appearance Syntax:

Void _setcursortye(int cur_T); _NOCURSOR (Turns off the cursor) _SOLIDCURSOR (solid block cursor)

_NORMALCURSOR (normal underscore cursor)

Eg: #include<stdio.h> #include<conio.h> Void main() { Clrscr(); Textmode(1); _setcursortype(_NOCURSOR); Textcolor(RED+BLINK); Textbackground(WHITE); Gotoxy(18,22); Cprintf(“welcome”); Getch(); } Text color:

Declaration:

Void textcolor(int newcolor) Textbackground:

It selects a new text background color. Declaration:

Void textbackground(int newcolor);

COLORS (text mode):

Constant Value Back-grd Fore-grnd BLACK 0 Yes Yes BLUE 1 Yes Yes

GREEN 2 Yes Yes

CYAN 3 Yes Yes RED 4 Yes Yes MAGENTA 5 Yes Yes

BROWN 6 Yes Yes

LIGHTGRAY 7 Yes Yes DARKGRAY 8 No Yes LIGHTBLUE 9 No Yes LIGHTGREEN 10 No Yes LIGHTCYAN 11 No Yes LIGHTRED 12 No Yes LIGHTMAGENTA 13 No Yes YELLOW 14 No Yes WHITE 15 No Yes BLINK 128 No ***

*** To display blinking characters in textmode, add BLINK to the foreground color.

If you want to display colors in textmode. We can use “cprintf” function. Cprintf:

It is same as printf to print colored formatted data output. Delay:

It suspends exectution for interval (milli seconds) Declaration:

Void delay(unsigned milliseconds); Kbhit:

It checks for currently available is keystrokes Declaration: Int kbhit(); Eg: #include<stdio.h> #include<conio.h> Void main() { Int c=1,c1=36,r=1; Textmode(1); _setcursortype(_NOCURSOR); While(!kbhit) { Textbackground(WHITE); Clrscr(); Textcolor(BLUE); Gotoxy(c,12); Cprintf(“RAJU”); Textcolor(“GREEN”);

Cprintf(“RANI”); Textcolor(“YELLOW”); Gotoxy(18,r); Cprintf(“WEDS”); C++; C1++; R++; If(c>36) { C=1; C1=36; } If(r>25) { R=1; } Delay(50); } }

Documento similar