-
/necesito sumar en un vector 10 elementos y mostrar la sumaasi ej
elemento 0 cantidad total …
elemento 1 cantidad total .../
....
#include<stdio.h>main()
{
int vector[10];
int i,s;for (i=0;i<10;i++)
{
vector_=0;
}for (i=0;i<10;i++)
{
printf ("Introduzca el numero en vector %d \n",i);scanf("%d ,%d",&vector_,&vector_);
}for (i=0;i<10;i++)
{
s=vector_+vector_;
printf(" el elemento %d",i);
printf("cantidad total %d",s);
printf("\n");
}getchar();
getchar();}_____</stdio.h>
-
Tengo el lenguaje C un poco oxidado y no entiendo muy bien lo que haces, pon el algoritmo para que se entienda mejor.
Suponiendo que lo que quieres es sumar un vector de 10 elementos que contienen números enteros al azar (introducidos por teclado) haría esto:
Algoritmo suma_vector es constantes max: entero=9; // Define siempre una variable MAX para evitarte cambiar código innecesariamente variables i, max, total: entero; vector: array [1..max] de entero; inicio i=0; total=0; //Inicializa siempre las variables que lo necesiten desde i <-- 0 hasta max hacer escribir('Introduce un número'); leer (num); vector[i] <-- num; total <-- total + num; escribir (' Posición: (i), cantidad:(num), total: (total) '); i <-- i + 1; fin_desde [/i]
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Registrarse Conectarse