[Solved] Sum of two array [closed]


NSArray *firstArray=[NSArray arrayWithObjects:@"1",@"2",@"3", nil];

NSArray *secondArray=[NSArray arrayWithObjects:@"10",@"20",@"30", nil];

NSMutableArray *sumArray=[NSMutableArray new];

for (NSInteger i=0; i<[firstArray count]; i++) {
    NSString *newValue=[NSString stringWithFormat:@"%ld",([[firstArray objectAtIndex:i]integerValue] + [[secondArray objectAtIndex:i]integerValue])];
    [sumArray addObject:newValue];
}

NSLog(@"sum=%@",sumArray);

Output is :

sum=(
    11,
    22,
    33
)

NOTE: both firstArray & secondArray must be of same size, and contain integers as string. Otherwise you need to modify…

solved Sum of two array [closed]