Docsity

8. ciclo while programacion c++, Diapositivas de Ingeniería Infórmatica

Vista previa parcial del texto

¡Descarga 8. ciclo while programacion c++ y más Diapositivas en PDF de Ingeniería Infórmatica solo en Docsity!

Lenguaje C – Estructura while

Estructuras de ControlEstructuras de Control

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

ESTRUCTURA CICLICA

while

La sentencia de control

while

, es un bucle o ciclo que repetirá un

proceso

mientras

que

se

cumpla

la^

expresión

condicional

denominada condición de salida.La condición se comprueba antes de realizar la sentencia o procesopor lo que el conjunto de instrucciones se realiza cero o más veces;mientras

que

la

evaluación

de

la

expresión

sea

verdadera

se

realizarán

las

instrucciones

agrupadas

Lenguaje C – Estructura while.

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

realizarán

las

instrucciones

agrupadas

Estructura general: while (

condición)

{

Proceso cíclico.

}

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

ESTRUCTURA CICLICA

while

El ciclo

while

se puede utilizar de la misma forma que un

for

, si

hacemos depender el número de ciclos de una variable de controlque se incremente o decremente.

En este caso es preferible

utilizar el

for

Imprime

los

números

de

10

hasta

1000

aumentando

de

5

en

5:

#include<iostream.h> void

main()

Lenguaje C – Estructura while

La variable de control i, comienza en 10

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

void

main() {

int

i; i=10;while

(i<=1000)

{

cout<<i<<endl;i+=5;

}

}

La variable de control i, comienza en 10

La condición de ejecución ciclo es que lavariable de control sea menor o igual a 1000

La variable de control i, se incrementacinco unidades en cada ciclo.

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(n); raizc(double

n)

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

1 *^1

x=^1

x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

3 *^3

x=^3

x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

4 *^4

x=^4

x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1; while

4 *^4

x=^4

x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1; while

x=4.

x=x-0.1;while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1; while

x=x+0.1; x=

while

(x*x

< n) x=x+0.01; x=x-0.01;return

x;

4,^

16,

18 4,^

17,

18 4,^

18,

18 4,^

x-0,

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1; while

x=4.

x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1; while

x=4.

x=x-0.01;return

x;

<stream.h> <iostream.h> raizc(double); main(

double

n; cout<<"Introduzca

un

número

para

calcular

su

raiz

cuadrada:

cin>>n;cout<<raizc(

raizc(double

Lenguaje C – Estructura while

INGENIERIA CATASTRAL Y GEODESIA

ING. YURI BERNAL PEÑAING. ASTRID PEÑARANDA

float

x=1; while

(x*x

< n) x=x+1; x=x-1;while

(x*x

< n) x=x+0.1; x=x-0.1; while

x=4.

x=x-0.01;return

x;