Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions perform bubble sort
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>

// function to return sum of elements
// in an array of size n
int sum(int arr[], int n)
{
int sum = 0; // initialize sum

// Iterate through all elements
// and add them to sum
for (int i = 0; i < n; i++)
sum += arr[i];

return sum;
}

int main()
{
int arr[] = {12, 3, 4, 15};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Sum of given array is %d", sum(arr, n));
return 0;
}