Displaying ./code/cs256su21code/jun22/arraySum.c/*
Given an array of integers, write a loop that will
calculate the sum of all the values of the array
*/
#include <stdio.h>
int main()
{
int nums[10] = {6, 64, 23, 17, 8, 49, 32, 18, 21, 10}; //sum should be 248
int sum = 0;
for(int i = 0; i < 10; i++){
sum = nums[i] + sum;
//sum += nums[i];
}
printf("Sum of all values of array is %d\n", sum);
return 0;
}
|