Jump to content

Sum and product of an array: Difference between revisions

no edit summary
No edit summary
Line 377:
product = 1
for i in arr do product *= i
 
=={{header|Objective-C}}==
{{works with|GCC|4.0.1 (apple)}}
Sum:
- (float) sum:(NSMutableArray *)array
{
int i, sum, value;
sum = 0;
value = 0;
for (i = 0; i < [array count]; i++) {
value = [[array objectAtIndex: i] intValue];
sum += value;
}
return suml;
}
 
Product:
- (float) prod:(NSMutableArray *)array
{
int i, prod, value;
prod = 0;
value = 0;
for (i = 0; i < [array count]; i++) {
value = [[array objectAtIndex: i] intValue];
prod *= value;
}
return suml;
}
 
=={{header|OCaml}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.