nombre tipo de dato int nmeros Enteros float
nombre tipo de dato int (números Enteros) float (números Flotantes) char (tipo carácter) Int cantidad; Int horas; Int cuota; Int stock; Float precio; Float peso;
int cantidad, horas, cuota; float precio, peso; cantidad = 5; // Le asigno un número a la variable Cantidad; horas = 10+20 // Le asigno 30 a la variable horas cuota = Cantidad // A cuota le asigno lo que tiene Cantidad precio= 2, 5 // A precio le asigno 2, 5 peso= precio + 5 // Esta bien asignado A medida que una variable recibe un valor, pierde su antiguo valor y queda con el nuevo!!!!
INTRODUCIR DATOS POR TECLADO Y MOSTRAR DATOS POR PANTALLA cout: cin: Int A; A=100; cout << ‘Hola este es un mensaje’; cout << A; Cout << ‘ El valor de la variable A es: ‘ << A; Cin >> A; Cout <<‘Ingrese un nuevo valor para A: ’; Cin >> A
Operadores de Comparación en C Sintaxis Nombre del operador a<b Operador Menor a <= b Operador menor igual a>b Operador Mayor a >= b Operador Mayor Igual a != b Operador Distinto a == b Operador igual a && b Operador Y a || b Operadro O
Operación Lógicas: Una comparación lógica devuelve VERDADERO o FALSO (true o false) (1 o 0) int A, B; char C; A= 10; B = 5; C= ‘R’ (A>B) ? (B == B) ? (A>10) ? (C != ‘J’) ? (A<(B+5) ) ? (C > ‘S’) ?
CONECTORES LOGICOS && (Y) Y(&&) Resultado ||(O) O(||) Resultado V V V V F F V F V F F V V F F F
Operación Lógicas conectores lógicos int A, B; A= 20; B = 5; (A==20) && (B>5) V F V && F F
Expresión Condicional IF - ELSE (si) If (CONDICION) { INSTRUCCIONES } ELSE { } INSTRUCCIONES … INSTRUCCIONES } INSTRUCCIONES …
Estructura de Repetición : While WHILE <condición> { insturcción 1 instrucción 2 instrucción 3 } Instrucciones que se van a repetir
Estructura de Repetición : While int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . . ¿Cómo se ejecuta?
Estructura de Repetición : While i int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 0 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : WHILE i 0 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 0 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 1 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 1 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 1 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 2 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 2 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 2 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 3 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 3 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While i 3 int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i = i+1; }. . .
Estructura de Repetición : While int i; i=0; while (i < 3) { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : While char opcion; opcion='J' while (opcion { cout << != 'X') " " A B C X - Cargar un alumno nuevo" << endl; Eliminar un alumno del listado" << endl; Cargar notas de un alumno" << endl; Salir del programa" << endl; cout << " Ingrese una opción" << cin >> opcion; if (opción==A) {. . . } if (opción==B) {. . . } if (opción==C) {. . . } } endl;
Estructura de Repetición: FOR( inicialización, condición, incremento) { instrucción 1; instrucción 2; Instrucciones que se van a repetir instrucción 3; } Inicialización: condición: incremento:
Estructura de Repetición : FOR for(int i=0; i<3; i=i+1) { cout << “HOLA “ << endl; }. . . ¿Cómo se ejecuta?
Estructura de Repetición : FOR i 0 for(int i=0; i=0 i<3; i=i+1) { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : FOR i 0 for(int i=0; i<3 i=i+1) { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : FOR i 0 for(int i=0; i<3; i=i+1) { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : FOR i 1 for(int i=0; i<3; i=i+1) i=i+1 { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : FOR i 1 for(int i=0; i<3 i=i+1) { cout << “HOLA “ << endl; }. . .
Estructura de Repetición : FOR i 1 for(int i=0; i<3; i=i+1) { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 2 for(int i=0; i<3; i=i+1) i=i+1 { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 2 for(int i=0; i<3 i=i+1) { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 2 for(int i=0; i<3; i=i+1) { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 3 for(int i=0; i<3; i=i+1) i=i+1 { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 3 for(int i=0; i<3; <3 i=i+1) { cout << “HOLA“ << endl; }. . .
Estructura de Repetición : FOR i 3 for(int i=0; i<3; i=i+1) { cout << “HOLA“ << endl; }. . .
Estructura de Repetición: FOR( int i=50, i>0, i=i-2) { instrucción 1; instrucción 2; instrucción 3; } La variable i va a ir descontandose de 2 en dos: 50, 48, 46, …, 0
FORMAS CORTAS DE PONER INCREMENTADORES O DECREMENTADORES i=i+1 i=i-1 i++ i-- for(int i=0; i<3; i++) { cout << “HOLA “ << endl; }. . . int i; i=0; while (i < 3) { cout << “HOLA “ << endl; i++; }. . .
- Slides: 42