Advertisement
Guest User

suma de elementos

a guest
Sep 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. int suma(int , int [] );
  5.  
  6. void main(void)
  7.  
  8. {
  9.     int n, A[100], i;
  10.    int sum=0;
  11.  
  12.    cout<<"ingrese la cantidad de casilleros de un array: "<<endl;
  13.    cin>>n;
  14.  
  15.    for(i=1;i<=n;i++)
  16.    {
  17.     cout<<"ingrese el elemento del array: "<<endl;
  18.       cin>>A[i];
  19.  
  20.    }
  21.    suma(n,A)+A[n];
  22.  
  23.    cout<<"el resultado de la suma es: "<<suma(n,A)<<endl;
  24. getch();
  25. }
  26.  
  27. int suma(int n, int A[])
  28. {
  29.     if(n==1)
  30.     return A[1];
  31.    else
  32.     return suma(n-1,A)+A[n];
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement