Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Slide 9, Questão 1/b) - Arranjos

Francelmo Apr 6th, 2020 248 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. //Slide 9, Questão 1/b).
  3. int main(){
  4.     int vetor[20];
  5.     int i, max=0, min=0, cont=0, aux=0, aux2=0, soma=0;
  6.     float media;
  7.     printf("Digite valores para o vetor:\n");
  8.     for(i=0; i<20; i++){
  9.         scanf("%d", &vetor[i]);
  10.         cont = vetor[i];
  11.         soma += cont;
  12.     }
  13.   media = soma / 20.0;
  14.   cont=0;
  15.   for(i=0; i<20; i++){
  16.     if(vetor[i]<media)
  17.       min++;
  18.     else if(vetor[i]>media)
  19.       max++;
  20.     else
  21.       cont++;
  22.   }
  23.   int menor[min], maior[max];
  24.   for(i=0; i<20; i++)
  25.     if(vetor[i]<media){
  26.       menor[aux] = vetor[i];
  27.       aux++;
  28.     }
  29.     else{
  30.       maior[aux2] = vetor[i];
  31.       aux2++;
  32.     }
  33.   if(min>cont && max>cont){
  34.     printf("Vetor Menor: { ");
  35.     for(i=0; i<min; i++)
  36.       printf("%d ", menor[i]);
  37.     printf("}.\nVetor Maior: { ");
  38.     for(i=0; i<max; i++)
  39.       printf("%d ", maior[i]);
  40.     printf("}.\n");
  41.   }
  42.   else
  43.     printf("Os números do vetor são todos iguais a média!\n");
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top