Advertisement
ferseg

suma y multiplicacion de elementos de arreglo

Oct 9th, 2014
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. /*  Autor: Joel Cesar Fernandez Segura
  2.     Fecha: 28/08/2014
  3.     Tema: Vectores y Arreglos
  4. */
  5.  
  6. #include<iostream>
  7. #include<cstdlib>
  8. using namespace std;
  9. void mostrarArray(float []);
  10. float sumarElementos(float []);
  11. float multiplicarElementos(float []);
  12.  
  13. int main(void){
  14.  
  15.     float array[10];
  16.     float suma,multiplicacion;
  17.     system("color 0a");
  18.     cout<<"\n\t\t [ VECTORES EN C++ ]\n\n";
  19.     cout<<"\n[EJERCICIO #1]\n";
  20.     cout<<"\nOPERACIONES CON ELEMENTOS DE UN ARREGLO\n\n";
  21.     for(int i=0;i<10;i++){
  22.     cout<<"INGRESE ELEMENTO ["<<i+1<<"]:";
  23.     cin>>array[i];
  24.     }
  25.     cout<<"\n\nEL ARREGLO ES :\n";
  26.     mostrarArray(array);
  27.     cout<<endl<<endl<<endl;
  28.     suma=sumarElementos(array);
  29.     multiplicacion=multiplicarElementos(array);
  30.  
  31.     cout<<"LA SUMA DE ELEMENTOS ES: "<<suma;
  32.  
  33.     cout<<"\n\nLA MULTIPLICACION DE ELEMENTOS ES: "<<multiplicacion;
  34.     cout<<endl<<endl<<endl;
  35.     return 0;
  36. }
  37.  
  38. float sumarElementos(float array[]){
  39.     float suma=0;
  40.     for(int i=0;i<10;i++){
  41.        suma+=array[i] ;
  42.     }
  43.     return suma;
  44. }
  45.  
  46. float multiplicarElementos(float array[]){
  47.     float mult=1;
  48.     for(int i=0;i<10;i++){
  49.        mult*=array[i] ;
  50.     }
  51.     return mult;
  52. }
  53.  
  54. void mostrarArray(float array[]){
  55.  
  56.     for(int i=0;i<10;i++){
  57.     cout<<array[i]<<"  ";
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement