Promediar tres vectores

En estre ejemplo, verermos como realizar la suma de tres vectores y mostrar el promedio en un cuarto vector.

Codigo en PSEINT:

Algoritmo SumayPromedioDeVectores
    Dimension n1[8]
    Dimension n2[8]
    Dimension n3[8]
    Dimension pro[8]
    //Ingresa 8 notas al array n1, n2 y n3
    Para f = 1 hasta 8 con paso 1 hacer			
        Escribir "INGRESE 3 NOTAS : ", f 
        Escribir "Ingrese Nota 1: "
        Leer n1[f]
        Escribir "Ingrese Nota 2: "
        Leer n2[f]
        Escribir "Ingrese Nota 3: "
        Leer n3[f]
    FinPara		
    //Muestra y Calcula los tres promedios
    Para f = 1 hasta 8 con paso 1 hacer						
        Escribir n1[f]," + ",n2[f]," + ",n3[f]," = ",(n1[f]+n2[f]+n3[f])/3
    FinPara	
FinAlgoritmo

C++

#include<stdio.h>
int main() {
    int f;
    int n1[8];
    int n2[8];
    int n3[8];
    int pro[8];
    /* Ingresa 8 notas al array n1, n2 y n3 */
    for (f=0;f<=7;f+=1) {
        printf("\nINGRESE 3 NOTAS : %d\n",f+1);
        printf("Ingrese Nota 1: ");
        scanf("%i",&n1[f]);
        printf("Ingrese Nota 2: ");
        scanf("%i",&n2[f]);
        printf("Ingrese Nota 3: ");
        scanf("%i",&n3[f]);
    }
    /* Muestra y Calcula los tres promedios */
    printf("\n");
    for (f=0;f<=7;f+=1) {
        printf("%d+%d+%d=%d\n",n1[f],n2[f],n3[f],(n1[f]+n2[f]+n3[f])/3);
    }
    return 0;
}

JAVA

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] n1 = new int[8];
        int[] n2 = new int[8];
        int[] n3 = new int[8];

        // Ingresa 8 notas al array n1, n2 y n3
        for (int f = 0; f < 8; f++) {
            System.out.println("\nINGRESE 3 NOTAS : " + (f + 1));
            System.out.print("Ingrese Nota 1: ");
            n1[f] = scanner.nextInt();
            System.out.print("Ingrese Nota 2: ");
            n2[f] = scanner.nextInt();
            System.out.print("Ingrese Nota 3: ");
            n3[f] = scanner.nextInt();
        }

        // Muestra y calcula los tres promedios
        System.out.println();
        for (int f = 0; f < 8; f++) {
            int promedio = (n1[f] + n2[f] + n3[f]) / 3;
            System.out.println(n1[f] + "+" + n2[f] + "+" + n3[f] + "=" + promedio);
        }

        scanner.close();
    }
}
0 Shares:
Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *