C++: Calculer la somme partielle d’un tableau

Author:

 calcul
Download


#include 
#include 
#include 
using namespace std;

int main()
{
  int tab1[10], tab2[10];

  for (int i = 0; i < 10; ++i)
  {
    tab1[i] = i + 1;
  }

  /*
   Calculer la somme partielle du tableau tab1
   et enregistrer les résultats dans 'tab2'
   Formule: *first + *(first + 1)
   */
  partial_sum(&tab1[0], &tab1[10], &tab2[0]);

  for (i = 0; i < 10; ++i)
    cout << tab2[i] << " ";

  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *