Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct producto{
  5. char nombre[100]; // 1 bytes * 100
  6. float precio; // 4 bytes
  7.  
  8. struct {
  9. char nombre[60];
  10. float lat,lng;
  11. } origen;
  12. };
  13.  
  14. void mostrarInformacionDelProducto(struct producto p){
  15. printf("Producto: %s proveniente de %s \n -> Precio : %f \n\n",
  16. p.nombre, p.origen.nombre, p.precio);
  17. }
  18.  
  19. void asignarAProducto(struct producto *P,
  20. char *nombre, float precio,
  21. char *origen, float lat, float lng){
  22.  
  23. strcpy(P->nombre , nombre);
  24. strcpy(P->origen.nombre , origen);
  25. P->precio = precio;
  26. P->origen.lat = lat;
  27. P->origen.lng = lng;
  28. }
  29.  
  30.  
  31.  
  32. int main(){
  33. struct producto P[10];
  34. int i;
  35. float a,b,c;
  36. char str1[100], str2[100];
  37.  
  38. printf("La estructura ocupa %d bytes en memoria.\n",
  39. sizeof(struct producto));
  40.  
  41. // Como cargar 5 datos
  42. for (i = 0; i < 5; i++){
  43. printf("Producto %d", i);
  44.  
  45. printf("\nIngrese el nombre del producto: ");
  46. scanf("%s", str1); fflush(stdin);
  47.  
  48. printf("Ingrese el nombre del origen: ");
  49. scanf("%s", str2); fflush(stdin);
  50.  
  51. printf("Ingrese el precio: ");
  52. scanf("%f", &a); fflush(stdin);
  53.  
  54. printf("Ingrese la latitud: ");
  55. scanf("%f", &b); fflush(stdin);
  56.  
  57. printf("Ingrese el longitud: ");
  58. scanf("%f", &c); fflush(stdin);
  59.  
  60. printf("\n");
  61.  
  62. asignarAProducto(&P[i], str1, a, str2, b, c);
  63. mostrarInformacionDelProducto(P[i]);
  64. }
  65.  
  66. /*
  67. // Asignacion caso particular en el main
  68. strcpy(P[0].nombre , "Alfajor");
  69. strcpy(P[0].origen.nombre , "Arcor");
  70. P[0].precio = 19.99;
  71. P[0].origen.lat = 23.3;
  72. P[0].origen.lng = 42.3;
  73.  
  74. // Asignacion caso particular a traves de la funcion
  75. asignarAProducto(&P[0], "Alfajor",19.99, "Arcor",
  76. 23.3, 42.3);
  77.  
  78. // Mostrar elemento i=0
  79. mostrarInformacionDelProducto(P[0]);
  80. */
  81.  
  82. return 0;
  83. }
  84.  
  85. /*
  86.  
  87.  
  88. #include <stdio.h>
  89. #include <string.h>
  90.  
  91. struct nombre{
  92. char cad[100];
  93. };
  94.  
  95. int main(){
  96. int i=0;
  97. char *ptr;
  98. struct nombre A,*B, C[10];
  99.  
  100. strcpy(A.cad, "Valentina");
  101.  
  102. for (ptr = A.cad ;*ptr!=0;ptr++);
  103.  
  104. printf("El nombre de A es %s y tiene %d caracteres \n",
  105. A.cad, (int)(ptr - A.cad));
  106.  
  107. printf("")
  108.  
  109.  
  110.  
  111. return 0;
  112. }
  113.  
  114. */
  115.  
  116. /*
  117. #include <stdio.h>
  118. void ImprimirCaracter(char caracter);
  119. void ImprimirCaracteres(char, int);
  120. void ImprimirFilas(char, int, int);
  121.  
  122. void ImprimirCaracter(char caracter){
  123. printf("%c", caracter);
  124. }
  125.  
  126. void ImprimirCaracteres(char c, int n){
  127. int i;
  128. if (c == 0) return;
  129. for (i = 0; i < n; i++)
  130. ImprimirCaracter(c);
  131. }
  132.  
  133. void ImprimirFila(char caracter, int vecesEspacio,
  134. int vecesCaracter){
  135. ImprimirCaracteres(' ', vecesEspacio);
  136. ImprimirCaracteres(caracter, vecesCaracter);
  137. printf("\n");
  138. }
  139.  
  140. void ImprimirPiramide(int F){
  141. int i;
  142. for(i = 0; i < F; i++)
  143. ImprimirFila('*', F-1-i, i+1);
  144. }
  145.  
  146. int main(){
  147. ImprimirPiramide(40);
  148. return 0;
  149. }
  150. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement