Skip to main content
Search
Search This Blog
Livecodo
Pages
Home
Courses
Blog
About us
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
May 02, 2024
Write a c program to sort the given n integers and perform following operations i)Find the products of every two odd position Elements ii)Find the sum of every two even position elements
#include
int bubbleSort(int arr[], int n) { for (int i = 0; i < n-1; i++) { for (int j = 0; j < n-i-1; j++) { if (arr[j] > arr[j+1]) { int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } int main() { int n; printf("Enter the number of integers: "); scanf("%d", &n); int arr[n]; printf("Enter %d integers:\n", n); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } // Sorting the array bubbleSort(arr, n); printf("Product: "); long long product_odd = 1; for (int i = 1; i < n; i += 2) { product_odd = arr[i]*arr[i+2]; if(i+2
Popular Posts
March 26, 2024
Dynamic Memory allocation in C
May 18, 2024
Searching and sorting Algorithm in C