How to represent algorithm in C for Pseudocode?

Asked

Viewed 1,614 times

2

I have the following code :

setlocale(LC_ALL,"portuguese");

int numeros[5];
int media;

for(int i = 0; i < 5; i++) {
    printf("Digite um número : ");
    scanf("%d", &numeros[i]);
}

media = numeros[0] + numeros[1] + numeros[2] + numeros[3] + numeros[4];

printf("\nMedia : %d \n\n", media);
printf("Número 1 : %d \n", numeros[0]);
printf("Número 2 : %d \n", numeros[1]);
printf("Número 3 : %d \n", numeros[2]);
printf("Número 4 : %d \n", numeros[3]);
printf("Número 5 : %d \n", numeros[4]);

I need to pass this code to Pseudocode, but I can’t remember how to correctly represent the for.

  • for..................

  • 2

    If it is in this format, already has a repeat loop pseudocode in the first example.

1 answer

4


First, I want to make it clear that Pseudocode does not have a standard model, and its purpose is simply to represent a code so that people who see it can understand it easily. So if you do not like the model I made here, I believe that you do not deserve -1 because as I said above, there is no pattern, if you want to add something more, please let me know.

InicioAlgoritmo

Variaveis

numero : vetor[1..5] de inteiro
media,i : inteiro

Inicio

para i de 1 ate 5 faca
escreval ("Digite um número");
leia(numeros[i]);
fimpara

media <- (numeros[0]+numeros[1]+numeros[2]+numeros[3]+numeros[4]) / 5;

para i de 1 ate 5 faca
escreval("Número : %d %d, i+1, numeros[i]);
fimpara

FimAlgoritmo
  • 2

    That’s exactly what I wanted, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.