• 0
Sign in to follow this  
Arthur Menezes

Erro de calculo ao exibir msg

Question

Ae galera meu professor pediu um trabalho em c++ um exercício é para ler n numeros... exibir a media desses numeros e o maior e menor... mas a soma dos elementos do vetor na ta saindo certa... alguém me ajuda?

Vlw

segue o codigo:

#include <iostream.h>

#include <stdlib.h>

const int arrayTAM = 3;

int num[arrayTAM];

int soma=0, i=0;

int aux, j;

float media;

int main(void)

{

for(i=0; i<= arrayTAM ; i++)

{

cout<<"Digite um numero: ";

cin>> num;

soma += num;

}

float media= soma/(arrayTAM+1);

for(i=0; i<=arrayTAM+1; i++)

{

if(num > num[i+1])

{

aux = num;

num = num[i+1];

num[i+1] = aux;

}

}

cout<<"A media dos "<<arrayTAM + 1<<" numeros e:"<<media<<endl;

cout<<"O menor numero e: "<<num[0]<<endl;

cout<<"O maior numero e: "<<num[arrayTAM]<<endl;

system("pause");

}

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this