57 lines
1.8 KiB
Plaintext
57 lines
1.8 KiB
Plaintext
|
//**************************************************************//
|
||
|
// //
|
||
|
// Program: Concurrent Add Exercise //
|
||
|
// Filename: add.cm //
|
||
|
// Original author: Neil Bergmann //
|
||
|
// Modification: Tracy Camp //
|
||
|
// //
|
||
|
// This program is a concurrent add example for use with //
|
||
|
// the BACI system. In its current version, it gives //
|
||
|
// indeterminate, incorrect answers. //
|
||
|
// //
|
||
|
// You need to add additional code to this file; do NOT //
|
||
|
// delete, replace, or modify existing code. //
|
||
|
// //
|
||
|
//**************************************************************//
|
||
|
|
||
|
//Global Variable Declarations //
|
||
|
|
||
|
int total; //Global variable to hold accumulating total//
|
||
|
|
||
|
//**************************************************************//
|
||
|
void add(int lower, int upper)
|
||
|
//Adds numbers in the range lower to upper inclusive to total//
|
||
|
|
||
|
{
|
||
|
int i;
|
||
|
for (i=lower;i<=upper;i++)
|
||
|
{
|
||
|
total = total + i;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//**************************************************************//
|
||
|
void initialize()
|
||
|
//Initializes all global variables and data structures//
|
||
|
|
||
|
{
|
||
|
total = 0;
|
||
|
}
|
||
|
|
||
|
//**************************************************************//
|
||
|
//main program//
|
||
|
|
||
|
main() {
|
||
|
|
||
|
cobegin {
|
||
|
add(1,10); add(11,20); add(21,30); add(31,40); add(41,50);
|
||
|
add(51,60); add(61,70); add(71,80); add(81,90); add(91,100);
|
||
|
}
|
||
|
|
||
|
cout << "Sum [1..100] = " << total << endl;
|
||
|
|
||
|
} //main program//
|
||
|
|
||
|
//**************************************************************//
|
||
|
|