Glaas2

Productos

Aug 29th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define num 5
  5.  
  6. struct Productos{
  7.        float precio;
  8.        char nombre[20];
  9.        char marca[20];
  10.        };
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.   struct Productos *prod;    
  15.   prod=(struct Productos*)malloc(sizeof(struct Productos)*num);
  16.   int i;
  17.  
  18.   strcpy(prod[0].marca, "Apple");
  19.   strcpy(prod[0].nombre, "IPhone 4g");
  20.   prod[0].precio=9500.50f;
  21.  
  22.   strcpy(prod[1].marca, "Sony");
  23.   strcpy(prod[1].nombre, "Playstation 3");
  24.   prod[1].precio=9350.86f;
  25.  
  26.   strcpy(prod[2].marca, "Acer");
  27.   strcpy(prod[2].nombre, "Acer Aspire 4225");
  28.   prod[2].precio=7400.43f;
  29.  
  30.   strcpy(prod[3].marca, "Apple");
  31.   strcpy(prod[3].nombre, "IPod Touch 4g");
  32.   prod[3].precio=4600.50f;
  33.  
  34.   strcpy(prod[4].marca, "Sony Ericcson");
  35.   strcpy(prod[4].nombre, "Xperia Pro");
  36.   prod[4].precio=5300.87f;
  37.  
  38.   printf("Nombre_Producto\t\tMarca\t\t\t\tPrecio\n\n\n");
  39.   for(i=0;i<num;i++)
  40.   printf("%-20s\t%-20s\t\t%-20.2f\n\n", prod[i].nombre, prod[i].marca, prod[i].precio);
  41.  
  42.   system("PAUSE"); 
  43.   return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment