WeixiangYan/CodeTransOcean huggingface dataset:
Task: XML_Output




Go: package main

import (
    "encoding/xml"
    "fmt"
)


func xRemarks(r CharacterRemarks) (string, error) {
    b, err := xml.MarshalIndent(r, "", "    ")
    return string(b), err
}



type CharacterRemarks struct {
    Character []crm
}

type crm struct {
    Name   string `xml:"name,attr"`
    Remark string `xml:",chardata"`
}

func main() {
    x, err := xRemarks(CharacterRemarks{[]crm{
        {`April`, `Bubbly: I'm > Tam and <= Emily`},
        {`Tam O'Shanter`, `Burns: "When chapman billies leave the street ..."`},
        {`Emily`, `Short & shrift`},
    }})
    if err != nil {
        x = err.Error()
    }
    fmt.Println(x)
}








Ada: with Ada.Strings.Unbounded;
with Ada.Text_IO.Text_Streams;
with DOM.Core.Documents;
with DOM.Core.Elements;
with DOM.Core.Nodes;

procedure Character_Remarks is
   package DC renames DOM.Core;
   package IO renames Ada.Text_IO;
   package US renames Ada.Strings.Unbounded;
   type Remarks is record
      Name : US.Unbounded_String;
      Text : US.Unbounded_String;
   end record;
   type Remark_List is array (Positive range <>) of Remarks;
   My_Remarks : Remark_List :=
      ((US.To_Unbounded_String ("April"),
        US.To_Unbounded_String ("Bubbly: I'm > Tam and <= Emily")),
       (US.To_Unbounded_String ("Tam O'Shanter"),
        US.To_Unbounded_String ("Burns: ""When chapman billies leave the street ...""")),
       (US.To_Unbounded_String ("Emily"),
        US.To_Unbounded_String ("Short & shrift")));
   My_Implementation : DC.DOM_Implementation;
   My_Document       : DC.Document := DC.Create_Document (My_Implementation);
   My_Root_Node      : DC.Element  := DC.Nodes.Append_Child (My_Document,
                                         DC.Documents.Create_Element (My_Document, "CharacterRemarks"));
   My_Element_Node   : DC.Element;
   My_Text_Node      : DC.Text;
begin
   for I in My_Remarks'Range loop
      My_Element_Node := DC.Nodes.Append_Child (My_Root_Node,
                            DC.Documents.Create_Element (My_Document, "Character"));
      DC.Elements.Set_Attribute (My_Element_Node, "Name", US.To_String (My_Remarks (I).Name));
      My_Text_Node    := DC.Nodes.Append_Child (My_Element_Node,
                            DC.Documents.Create_Text_Node (My_Document, US.To_String (My_Remarks (I).Text)));
   end loop;
   DC.Nodes.Write (IO.Text_Streams.Stream (IO.Standard_Output),
                   N => My_Document,
                   Pretty_Print => True);
end Character_Remarks;
Task: XML_Output







Python: >>> from xml.etree import ElementTree as ET
>>> from itertools import izip
>>> def characterstoxml(names, remarks):
	root = ET.Element("CharacterRemarks")
	for name, remark in izip(names, remarks):
		c = ET.SubElement(root, "Character", {'name': name})
		c.text = remark
	return ET.tostring(root)

>>> print characterstoxml(
	names = ["April", "Tam O'Shanter", "Emily"],
	remarks = [ "Bubbly: I'm > Tam and <= Emily",
		    'Burns: "When chapman billies leave the street ..."',
		    'Short & shrift' ] ).replace('><','>\n<')





Ada: with Ada.Strings.Unbounded;
with Ada.Text_IO.Text_Streams;
with DOM.Core.Documents;
with DOM.Core.Elements;
with DOM.Core.Nodes;

procedure Character_Remarks is
   package DC renames DOM.Core;
   package IO renames Ada.Text_IO;
   package US renames Ada.Strings.Unbounded;
   type Remarks is record
      Name : US.Unbounded_String;
      Text : US.Unbounded_String;
   end record;
   type Remark_List is array (Positive range <>) of Remarks;
   My_Remarks : Remark_List :=
      ((US.To_Unbounded_String ("April"),
        US.To_Unbounded_String ("Bubbly: I'm > Tam and <= Emily")),
       (US.To_Unbounded_String ("Tam O'Shanter"),
        US.To_Unbounded_String ("Burns: ""When chapman billies leave the street ...""")),
       (US.To_Unbounded_String ("Emily"),
        US.To_Unbounded_String ("Short & shrift")));
   My_Implementation : DC.DOM_Implementation;
   My_Document       : DC.Document := DC.Create_Document (My_Implementation);
   My_Root_Node      : DC.Element  := DC.Nodes.Append_Child (My_Document,
                                         DC.Documents.Create_Element (My_Document, "CharacterRemarks"));
   My_Element_Node   : DC.Element;
   My_Text_Node      : DC.Text;
begin
   for I in My_Remarks'Range loop
      My_Element_Node := DC.Nodes.Append_Child (My_Root_Node,
                            DC.Documents.Create_Element (My_Document, "Character"));
      DC.Elements.Set_Attribute (My_Element_Node, "Name", US.To_String (My_Remarks (I).Name));
      My_Text_Node    := DC.Nodes.Append_Child (My_Element_Node,
                            DC.Documents.Create_Text_Node (My_Document, US.To_String (My_Remarks (I).Text)));
   end loop;
   DC.Nodes.Write (IO.Text_Streams.Stream (IO.Standard_Output),
                   N => My_Document,
                   Pretty_Print => True);
end Character_Remarks;
Task: XML_Output








VB: Module XMLOutput
    Sub Main()
        Dim charRemarks As New Dictionary(Of String, String)
        charRemarks.Add("April", "Bubbly: I
        charRemarks.Add("Tam O
        charRemarks.Add("Emily", "Short & shrift")

        Dim xml = <CharacterRemarks>
                      <%= From cr In charRemarks Select <Character name=<%= cr.Key %>><%= cr.Value %></Character> %>
                  </CharacterRemarks>

        Console.WriteLine(xml)
    End Sub
End Module




Ada: with Ada.Strings.Unbounded;
with Ada.Text_IO.Text_Streams;
with DOM.Core.Documents;
with DOM.Core.Elements;
with DOM.Core.Nodes;

procedure Character_Remarks is
   package DC renames DOM.Core;
   package IO renames Ada.Text_IO;
   package US renames Ada.Strings.Unbounded;
   type Remarks is record
      Name : US.Unbounded_String;
      Text : US.Unbounded_String;
   end record;
   type Remark_List is array (Positive range <>) of Remarks;
   My_Remarks : Remark_List :=
      ((US.To_Unbounded_String ("April"),
        US.To_Unbounded_String ("Bubbly: I'm > Tam and <= Emily")),
       (US.To_Unbounded_String ("Tam O'Shanter"),
        US.To_Unbounded_String ("Burns: ""When chapman billies leave the street ...""")),
       (US.To_Unbounded_String ("Emily"),
        US.To_Unbounded_String ("Short & shrift")));
   My_Implementation : DC.DOM_Implementation;
   My_Document       : DC.Document := DC.Create_Document (My_Implementation);
   My_Root_Node      : DC.Element  := DC.Nodes.Append_Child (My_Document,
                                         DC.Documents.Create_Element (My_Document, "CharacterRemarks"));
   My_Element_Node   : DC.Element;
   My_Text_Node      : DC.Text;
begin
   for I in My_Remarks'Range loop
      My_Element_Node := DC.Nodes.Append_Child (My_Root_Node,
                            DC.Documents.Create_Element (My_Document, "Character"));
      DC.Elements.Set_Attribute (My_Element_Node, "Name", US.To_String (My_Remarks (I).Name));
      My_Text_Node    := DC.Nodes.Append_Child (My_Element_Node,
                            DC.Documents.Create_Text_Node (My_Document, US.To_String (My_Remarks (I).Text)));
   end loop;
   DC.Nodes.Write (IO.Text_Streams.Stream (IO.Standard_Output),
                   N => My_Document,
                   Pretty_Print => True);
end Character_Remarks;
Task: XML_Output

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

const char *names[] = {
  "April", "Tam O'Shanter", "Emily", NULL
};
const char *remarks[] = {
  "Bubbly: I'm > Tam and <= Emily",
  "Burns: \"When chapman billies leave the street ...\"",
  "Short & shrift", NULL
};

int main()
{
  xmlDoc *doc = NULL;
  xmlNode *root = NULL, *node;
  const char **next;
  int a;

  doc = xmlNewDoc("1.0");
  root = xmlNewNode(NULL, "CharacterRemarks");
  xmlDocSetRootElement(doc, root);

  for(next = names, a = 0; *next != NULL; next++, a++) {
    node = xmlNewNode(NULL, "Character");
    (void)xmlNewProp(node, "name", *next);
    xmlAddChild(node, xmlNewText(remarks[a]));
    xmlAddChild(root, node);
  }

  xmlElemDump(stdout, doc, root);

  xmlFreeDoc(doc);
  xmlCleanupParser();
  
  return EXIT_SUCCESS;
}
Task: XML_Output



C#: using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class Program
{
    static string CreateXML(Dictionary<string, string> characterRemarks)
    {
        var remarks = characterRemarks.Select(r => new XElement("Character", r.Value, new XAttribute("Name", r.Key)));
        var xml = new XElement("CharacterRemarks", remarks);
        return xml.ToString();
    }

    static void Main(string[] args)
    {
        var characterRemarks = new Dictionary<string, string>
        {
            { "April", "Bubbly: I'm > Tam and <= Emily" },
            { "Tam O'Shanter", "Burns: \"When chapman billies leave the street ...\"" },
            { "Emily", "Short & shrift" }
        };

        string xml = CreateXML(characterRemarks);
        Console.WriteLine(xml);
    }
}
Task: XML_Output


C++: #include <vector>
#include <utility>
#include <iostream>
#include <boost/algorithm/string.hpp>

std::string create_xml( std::vector<std::string> & ,std::vector<std::string> & ) ;

int main( ) {
   std::vector<std::string> names , remarks ;
   names.push_back( "April" ) ;
   names.push_back( "Tam O'Shantor" ) ;
   names.push_back ( "Emily" ) ;
   remarks.push_back( "Bubbly, I'm > Tam and <= Emily" ) ;
   remarks.push_back( "Burns: \"When chapman billies leave the street ...\"" ) ;
   remarks.push_back( "Short & shrift" ) ;
   std::cout << "This is in XML:\n" ;
   std::cout << create_xml( names , remarks ) << std::endl ;
   return 0 ;
}

std::string create_xml( std::vector<std::string> & names ,
      std::vector<std::string> & remarks ) {
   std::vector<std::pair<std::string , std::string> > entities ;
   entities.push_back( std::make_pair( "&" , "&amp;" ) ) ;
   entities.push_back( std::make_pair( "<" , "&lt;" ) ) ;
   entities.push_back( std::make_pair( ">" , "&gt;" ) ) ;
   std::string xmlstring ( "<CharacterRemarks>\n" ) ;
   std::vector<std::string>::iterator vsi = names.begin( ) ;
   typedef std::vector<std::pair<std::string , std::string> >::iterator Vpss ;
   for ( ; vsi != names.end( ) ; vsi++ ) {
      for ( Vpss vs = entities.begin( ) ; vs != entities.end( ) ; vs++ ) {
	 boost::replace_all ( *vsi , vs->first , vs->second ) ;
      }
   }
   for ( vsi = remarks.begin( ) ; vsi != remarks.end( ) ; vsi++ ) {
      for ( Vpss vs = entities.begin( ) ; vs != entities.end( ) ; vs++ ) {
	 boost::replace_all ( *vsi , vs->first , vs->second ) ;
      }
   }
   for ( int i = 0 ; i < names.size( ) ; i++ ) {
      xmlstring.append( "\t<Character name=\"").append( names[ i ] ).append( "\">")
	 .append( remarks[ i ] ).append( "</Character>\n" ) ;
   }
   xmlstring.append( "</CharacterRemarks>" ) ;
   return xmlstring ;
}
Task: XML_Output





Java: import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class XmlCreation {

  private static final String[] names = {"April", "Tam O'Shanter", "Emily"};
  private static final String[] remarks = {"Bubbly: I'm > Tam and <= Emily",
    "Burns: \"When chapman billies leave the street ...\"",
      "Short & shrift"};
  
  public static void main(String[] args) {
    try {
      
      final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
      
      
      final Element root = doc.createElement("CharacterRemarks");
      doc.appendChild(root);
      
      
      for(int i = 0; i < names.length; i++) {
        final Element character = doc.createElement("Character");
        root.appendChild(character);
        character.setAttribute("name", names[i]);
        character.appendChild(doc.createTextNode(remarks[i]));
      }
      
      
      
      final Source source = new DOMSource(doc);
      
      
      final StringWriter buffer = new StringWriter();
      
      
      final Result result = new StreamResult(buffer);
      
      
      final Transformer transformer = TransformerFactory.newInstance().newTransformer();
      transformer.setOutputProperty("indent", "yes");
      transformer.transform(source, result);
      
      
      
      System.out.println(buffer.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  
}
Task: XML_Output







Python: >>> from xml.etree import ElementTree as ET
>>> from itertools import izip
>>> def characterstoxml(names, remarks):
	root = ET.Element("CharacterRemarks")
	for name, remark in izip(names, remarks):
		c = ET.SubElement(root, "Character", {'name': name})
		c.text = remark
	return ET.tostring(root)

>>> print characterstoxml(
	names = ["April", "Tam O'Shanter", "Emily"],
	remarks = [ "Bubbly: I'm > Tam and <= Emily",
		    'Burns: "When chapman billies leave the street ..."',
		    'Short & shrift' ] ).replace('><','>\n<')
Task: XML_Output








VB: Module XMLOutput
    Sub Main()
        Dim charRemarks As New Dictionary(Of String, String)
        charRemarks.Add("April", "Bubbly: I
        charRemarks.Add("Tam O
        charRemarks.Add("Emily", "Short & shrift")

        Dim xml = <CharacterRemarks>
                      <%= From cr In charRemarks Select <Character name=<%= cr.Key %>><%= cr.Value %></Character> %>
                  </CharacterRemarks>

        Console.WriteLine(xml)
    End Sub
End Module
Task: XML_Output




Go: package main

import (
    "encoding/xml"
    "fmt"
)


func xRemarks(r CharacterRemarks) (string, error) {
    b, err := xml.MarshalIndent(r, "", "    ")
    return string(b), err
}



type CharacterRemarks struct {
    Character []crm
}

type crm struct {
    Name   string `xml:"name,attr"`
    Remark string `xml:",chardata"`
}

func main() {
    x, err := xRemarks(CharacterRemarks{[]crm{
        {`April`, `Bubbly: I'm > Tam and <= Emily`},
        {`Tam O'Shanter`, `Burns: "When chapman billies leave the street ..."`},
        {`Emily`, `Short & shrift`},
    }})
    if err != nil {
        x = err.Error()
    }
    fmt.Println(x)
}
Task: Sum and product of an array



C#: int sum = 0, prod = 1;
int[] arg = { 1, 2, 3, 4, 5 };
foreach (int value in arg) {
  sum += value;
  prod *= value;
}









Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array

C: 
int arg[] = { 1,2,3,4,5 };
int arg_length = sizeof(arg)/sizeof(arg[0]);
int *end = arg+arg_length;
int sum = 0, prod = 1;
int *p;

for (p = arg; p!=end; ++p) {
   sum += *p;
   prod *= *p;
}











Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array


C++: #include <numeric>
#include <functional>

int arg[] = { 1, 2, 3, 4, 5 };
int sum  = std::accumulate(arg, arg+5, 0, std::plus<int>());



int prod = std::accumulate(arg, arg+5, 1, std::multiplies<int>());










Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array




Go: package main

import "fmt"

func main() {
    sum, prod := 0, 1
    for _, x := range []int{1,2,5} {
        sum += x
        prod *= x
    }
    fmt.Println(sum, prod)
}








Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array





Java: public class SumProd
{
 public static void main(final String[] args)
 {
  int sum = 0;
  int prod = 1;
  int[] arg = {1,2,3,4,5};
  for (int i : arg)
  {
   sum += i;
   prod *= i;
  }
 }
}







Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array







Python: numbers = [1, 2, 3]
total = sum(numbers)

product = 1
for i in numbers:
    product *= i





Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array








VB: Sub Demo()
Dim arr
    arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Debug.Print "sum : " & Application.WorksheetFunction.Sum(arr)
    Debug.Print "product : " & Application.WorksheetFunction.Product(arr)
End Sub




Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array

C: 
int arg[] = { 1,2,3,4,5 };
int arg_length = sizeof(arg)/sizeof(arg[0]);
int *end = arg+arg_length;
int sum = 0, prod = 1;
int *p;

for (p = arg; p!=end; ++p) {
   sum += *p;
   prod *= *p;
}
Task: Sum and product of an array



C#: int sum = 0, prod = 1;
int[] arg = { 1, 2, 3, 4, 5 };
foreach (int value in arg) {
  sum += value;
  prod *= value;
}
Task: Sum and product of an array


C++: #include <numeric>
#include <functional>

int arg[] = { 1, 2, 3, 4, 5 };
int sum  = std::accumulate(arg, arg+5, 0, std::plus<int>());



int prod = std::accumulate(arg, arg+5, 1, std::multiplies<int>());
Task: Sum and product of an array





Java: public class SumProd
{
 public static void main(final String[] args)
 {
  int sum = 0;
  int prod = 1;
  int[] arg = {1,2,3,4,5};
  for (int i : arg)
  {
   sum += i;
   prod *= i;
  }
 }
}
Task: Sum and product of an array







Python: numbers = [1, 2, 3]
total = sum(numbers)

product = 1
for i in numbers:
    product *= i
Task: Sum and product of an array








VB: Sub Demo()
Dim arr
    arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Debug.Print "sum : " & Application.WorksheetFunction.Sum(arr)
    Debug.Print "product : " & Application.WorksheetFunction.Product(arr)
End Sub
Task: Sum and product of an array




Go: package main

import "fmt"

func main() {
    sum, prod := 0, 1
    for _, x := range []int{1,2,5} {
        sum += x
        prod *= x
    }
    fmt.Println(sum, prod)
}
Task: Sum and product of an array



C#: int sum = 0, prod = 1;
int[] arg = { 1, 2, 3, 4, 5 };
foreach (int value in arg) {
  sum += value;
  prod *= value;
}








Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array


C++: #include <numeric>
#include <functional>

int arg[] = { 1, 2, 3, 4, 5 };
int sum  = std::accumulate(arg, arg+5, 0, std::plus<int>());



int prod = std::accumulate(arg, arg+5, 1, std::multiplies<int>());









Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array

C: 
int arg[] = { 1,2,3,4,5 };
int arg_length = sizeof(arg)/sizeof(arg[0]);
int *end = arg+arg_length;
int sum = 0, prod = 1;
int *p;

for (p = arg; p!=end; ++p) {
   sum += *p;
   prod *= *p;
}










Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array





Java: public class SumProd
{
 public static void main(final String[] args)
 {
  int sum = 0;
  int prod = 1;
  int[] arg = {1,2,3,4,5};
  for (int i : arg)
  {
   sum += i;
   prod *= i;
  }
 }
}






Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array







Python: numbers = [1, 2, 3]
total = sum(numbers)

product = 1
for i in numbers:
    product *= i




Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array








VB: Sub Demo()
Dim arr
    arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Debug.Print "sum : " & Application.WorksheetFunction.Sum(arr)
    Debug.Print "product : " & Application.WorksheetFunction.Product(arr)
End Sub



Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array






PHP: $array = array(1,2,3,4,5,6,7,8,9);
echo array_sum($array);
echo array_product($array);





Fortran: integer, dimension(10) :: a = (/ (i, i=1, 10) /)
integer :: sresult, presult

sresult = sum(a)
presult = product(a)
Task: Sum and product of an array

C: 
int arg[] = { 1,2,3,4,5 };
int arg_length = sizeof(arg)/sizeof(arg[0]);
int *end = arg+arg_length;
int sum = 0, prod = 1;
int *p;

for (p = arg; p!=end; ++p) {
   sum += *p;
   prod *= *p;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array



C#: int sum = 0, prod = 1;
int[] arg = { 1, 2, 3, 4, 5 };
foreach (int value in arg) {
  sum += value;
  prod *= value;
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array


C++: #include <numeric>
#include <functional>

int arg[] = { 1, 2, 3, 4, 5 };
int sum  = std::accumulate(arg, arg+5, 0, std::plus<int>());



int prod = std::accumulate(arg, arg+5, 1, std::multiplies<int>());








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .