laialii

Struct - Banda

Feb 13th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. /*Essa estrutura deve ter o nome da banda, que tipo de música ela toca,
  2. o número de integrantes e em que posição do ranking essa banda está
  3. dentre as suas 5 bandas favoritas.*/
  4. #include <stdio.h>
  5. #define MAX 100
  6. #define NUM 2
  7.  
  8. struct banda{
  9.     char nome_da_banda[MAX], tipo_de_musica[MAX];
  10.     int num_de_integrantes, posicao;
  11. }ranking[NUM];
  12.  
  13. void preenche(struct banda *pnt){
  14.     for(int i=0; i<NUM; i++){
  15.         printf("Nome da banda: ");
  16.         scanf(" %[^\n]", pnt->nome_da_banda[i]);
  17.         printf("Tipo de musica: ");
  18.         scanf(" %[^\n]", pnt->tipo_de_musica[i]);
  19.         printf("Numero de integrantes: ");
  20.         scanf("%d", &pnt->num_de_integrantes[i]);
  21.         printf("Posicao do ranking de suas 5 bandas preferidas (digite um numero de 1 a 5): ");
  22.         scanf("%d", &pnt->posicao[i]);
  23.         printf("\n");
  24.     }
  25. }
  26.  
  27. void imprime(struct banda *pnt){
  28.     for(int i=0; i<NUM; i++){
  29.         printf("\n%s", pnt[i].nome_da_banda);
  30.         printf("\n%s", pnt[i].tipo_de_musica);
  31.         printf("\n%d", pnt[i].num_de_integrantes);
  32.         printf("\n%d", pnt[i].posicao);
  33.     }
  34. }
  35.  
  36. int main(){
  37.     struct banda ranking;
  38.     struct banda *pnt;
  39.     preenche(&ranking);
  40.     imprime(&ranking);
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment