.


:




:

































 

 

 

 


5.




 

, , , . . , ( ). , . .

1
2
(1)
(0)
2
1
(1)
(0)

 

 


, , . , , .

. . , , . , .

if

if (. . ). :

(1)
(0)

 


:

if ( )

1

else

2

:

if ( )

 

, . 1: .

int a = 5, b = 10, max;

 
 
 
 
 
// 1:

max = a;

if (b > a)

max = b;

// 2:

 
 
 
 
 
if (a >= b)

max = a;

else

max = b;

 
 
 
 
 
 
 
 
 
 
 
 
2: .

int a = 5, b = 10, = 7, max;

// 1:

if (a >= b && a >= c)

max = a;

if (b >= a && b >= c)

max = b;

if (c >= a && c >= b)

max = c;

// 2:

 
 
 
 
 
 
 
 
 
if (a >= b && a >= c)

max = a;

else

if (b >= c)

max = b;

else

max = c;

// 3:

if (a >= b)

 
 
 
 
 
 
 
 
 
 
 
 
 
{

if (a >= c)

max = a;

else

max = c;

}

else

{

if (b >= c)

max = b;

else

max = c;

}

else max = c; 2 , :

// 4:

 
 
 
 
 
 
 
 
 
 
 
 
max = c;

if (a >= b)

{

if (a >= c)

max = a;

}

else

if (b >= c)

max = b;

 
 
 
 
 
 
 
 
 
 
 
 
if , else if, else. else if, . , , , .. , a < b, max c b:

max = c;

if (a >= b)

if (a >= c)

max = a;

else

if (b >= c)

max = b;

 

 
 
 
 
 
 
 
 
 
// 5 ( ):

max = a;

if (b > max)

max = b;

if (c > max)

max = c;

 

 

if, else-if, :

if ( 1)

1

else if ( 2)

2

else if ( 3)

3

...

else if ( N)

N

else

N+1

if . . , .

else- , . else- , () . else-if:

 
 
 
 
 
 
 
 
 
if (a >= b && a >= c)

max = a;

else if (b >= a && b >= c)

max = b;

else

max = c;

switch

switch, , . :

switch ()

{

case 1: [ 1]

case 2: [ 2]

case 3: [ 3]

...

case N: [ N]

[default: N+1]

}

, . , , .

switch:

1
N+1
1
2
2
N
N
...
3
3

 

 


, . , . . , , default, . , . break. . : .

#include <stdio.h>

void main()

{

int number;

printf( :\n);

scanf(%d, &number);

switch (number)

{

case 1: printf(); break;

case 2: printf(); break;

case 3: printf(); break;

case 4: printf(); break;

case 5: printf(); break;

case 6: printf(); break;

case 7: printf(); break;

default: printf( ); break;

}

}

case. case :

#include <stdio.h>

void main()

{

int number;

printf( :\n);

scanf(%d, &number);

switch (number)

{

case 1: case 2: case 3: case 4: case 5:

printf(); break;

case 6: case 7:

printf(!); break;

default: printf( ); break;

}

}

, . ( ), , . : , . . , , .

 

.
(1)
(0)
 
 
.
(1)
(0)
 
 

 


( ), ( ). , , , .

, , , , . .

, .

while

:

while ( )

 

, ( ). , , , .

. , .

1: 10000$ 10% . ?

#include <stdio.h>

void main()

{

float sum = 10000;

float sum2 = 2*sum;

int YearCount = 0;

while(sum < sum2)

{

sum += sum*0.1;

YearCount++;

}

printf( = %d, YearCount);

}

2: .

#include <stdio.h>

void main()

{

int number, half, div;

scanf(%d, &number);

half = number/2;

div =2;

while(div <= half)

{

if(number % div == 0)

printf(%d , div);

div++;

}

}





:


: 2016-04-03; !; : 662 |


:

:

, ,
==> ...

1295 - | 1257 -


© 2015-2024 lektsii.org - -

: 0.048 .