Advertisement
Kl43z

Tweets ESTRUCTURAS

Dec 3rd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #define SIZE 100
  3. struct twitter{
  4.         char nombre[120];
  5.         int tweets,retweets;
  6.     };
  7. void burbuja(int a, struct twitter users[]);
  8. int main(){
  9.     int i=0;
  10.     struct twitter users[100];
  11.     for (i=0;i<SIZE;i++){
  12.         printf ("Ingrese los datos para el %iĀ° usuario:\n", i+1);
  13.         printf ("Nombre: ");
  14.         scanf ("%s", users[i].nombre);
  15.         printf ("\nTweets: ");
  16.         scanf ("%d", &users[i].tweets);
  17.         printf ("\nRetweets: ");
  18.         scanf ("%d", &users[i].retweets);
  19.         }
  20.     printf ("Tweets desordenados: \n");
  21.     for (i=0;i<SIZE;i++){
  22.         printf ("Nombre: %s\nTWEETS: %d\nRetweets: %d\n", users[i].nombre,users[i].tweets, users[i].retweets);
  23.     }
  24.     burbuja(SIZE,users);
  25.     printf ("\n-----------------------------\n");
  26.     printf ("Tweets desordenados: \n");
  27.         for (i=0;i<SIZE;i++){
  28.         printf ("Nombre: %s\nTWEETS: %d\nRetweets: %d\n", users[i].nombre,users[i].tweets, users[i].retweets);
  29.     }
  30.     return 0;
  31. }
  32.  
  33.  
  34. void burbuja(int a, struct twitter users[]){
  35.         int p, j;
  36.           struct twitter aux;
  37.         for (p=1;p<SIZE;p++){
  38.                 for (j=0;j<SIZE-1;j++){
  39.                         if (users[j].tweets>users[j+1].tweets){
  40.                                 aux=users[j];
  41.                                 users[j]=users[j+1];
  42.                                 users[j+1]=aux;
  43.                         }
  44.                 }
  45.         }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement