From 05de53e33c092e4cb3f854a9981d50b0e4eecec1 Mon Sep 17 00:00:00 2001 From: AChakraborty13 <72927348+AChakraborty13@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:06:24 +0530 Subject: [PATCH] Create sum of elements in array using c Optimized Code for Getting Sum of Elements in an array quickly using c --- sum of elements in array using c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sum of elements in array using c diff --git a/sum of elements in array using c b/sum of elements in array using c new file mode 100644 index 00000000..8eac8eab --- /dev/null +++ b/sum of elements in array using c @@ -0,0 +1,19 @@ +#include + +int main() +{ + int array[10] = {1,2,3,4,5,6,7,8,9,0} + int sum, loop; + + sum = 0; + + for(loop = 9; loop>=0; loop--) + { + sum = sum + array[loop]; + } + + printf("Sum of array is %d ",sum); + + return 0; + }