.


:




:

































 

 

 

 





if...else () . . if-else if-else. switch.

Switch ( )

{

case 1:

;

case 2:

;

default:

;

}

 

. case 'a': , . , default. default , switch . break switch . switch , chr. .

 

//

#include <stdio.h>

void main(void)

{

int x, y;

char c;

printf(" 2 ");

scanf( %d %d %c, &x, &y, &c);

switch (c) {

case '+': printf("x + y = %3d\n, x+y);

break;

case '-': printf("x - y = %3d\n, x-y);

break;

case '*': printf("x * y = %3d\n, x*y);

break;

case '/': printf("x / y = %3d\n, x/y);

break;

default:

printf(" !\n);

}

}

while

.

: , , .

) :

while : while, , - , , ( , {} ). , while while ;.

while ( ) while ( ){

; ;

}

 

 
 

 


while

 

 

( )

 

.

.

 

1: 2:

index = 0; index = 0;

while (index++ < 10) while (index++ < 10) {

sum = 10*index + 2; sum = 10*index + 2;

printf ("sum = % d \n", sum); printf ("sum = % d \n", sum);

}

1 . 1 ( sum=102). 2 , .

, . , .

, , , . .

 

// while

#include <stdio.h>

void main(void)

{

int guess=1;

char res;

printf(" 1 100. ");

printf("\n , );

printf(\n , .\n);

printf(" %d?\n", guess);

while((res=getchar())!= '')

if(res!='\n')

printf(" %d?\n", ++guess);

printf(", !!!");

}

) ( . , , ). 1 .

do do {

; ;

while ( ); } while ( );

 

. .

 

 
 


Do while

 

 

 

:

1 2

do { while((ch = getchar())! = '\n')

ch = getchar(); putchar (ch);

putchar (ch);

} while(ch! = '\n')

 

getchar() , , . putchar , , , , .. , . : putchar(getchar()) .)

. , ( , , ).

, .





:


: 2016-11-23; !; : 569 |


:

:

, ,
==> ...

1507 - | 1487 -


© 2015-2024 lektsii.org - -

: 0.016 .