Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. //Arreglos:
  4. //Los arreglos estaticos solo aceptan valores literales
  5.  
  6. int suma ()
  7. {
  8. int uno = 5;
  9. int dos = 6;
  10. int resultado = uno + dos;
  11. cout << resultado << endl;
  12. return resultado;
  13. }
  14.  
  15. int main()
  16. {
  17. int array[5];
  18. char word[3];
  19.  
  20. //Los for cuentan con tres partes: definicion, condicion e iteracion
  21.  
  22. //Llenar un arreglo, forma 1:
  23. for (int i = 0; i < 5; i++)
  24. {
  25. array[i] = i;
  26.  
  27. cout << array[i] << endl;
  28. }
  29.  
  30. //forma 2:
  31. word[0] = 'a';
  32. word[1] = 's';
  33. word[2] = '\0';
  34. cout << word << endl;
  35. //Esto combierte a nuestro arreglo en un string
  36.  
  37.  
  38. //forma 3:
  39. float flotantes[4] = { 1.0f,1.1f,1.2f,1.3f };
  40. cout << flotantes[0,3] << endl;
  41.  
  42. //Segundo ejemplo de asignacion automatica
  43. short automatic[45];
  44. for (int i = 0; i < 45; ++i)
  45. {
  46. automatic[i] = i + 3;
  47. }
  48. cout << automatic[0,44] << endl;
  49. cin.get();
  50.  
  51. suma ();
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement