0

What is the segmentation fault with the following code

include <stdio.h> #include <stdlib.h> void swap(int *a, int *b) {     int temp;     temp = *a;     *a = *b;     *b = temp; } int partition(int arr[], int low, int high) {     int j, pivot, i;     pivot = arr[high];     i = low - 1;     for( j = low; j < high; j++)     {         if(arr[j] > pivot)         {             i++;             swap(&arr[i], &arr[j]);         }     }      swap(&arr[i + 1], &arr[high]);      return i+1; } void quicks(int arr[], int low,int high) { int pi;     if(low < high)     {         pi = partition(arr, low, high);         quicks(arr, low, pi-1);         quicks(arr, pi+1, high);     } } int main() {     int n, k, s, t, u, arr[10], sum=0, c=0,q;     scanf("%d %d %d", &n, &k, &s);     for(t = 0; t < n; t++)     {         scanf(" %d", &arr[t]);     }      q = k * s;     quicks(arr, 0, n-1);     for(u = 0; u < n; u++)     {         c++;         sum += arr[u];         if(sum >= q)             break;     } printf("%d", c); }   

20th Feb 2019, 12:44 PM
Vikram Vm
Vikram Vm - avatar
1 Réponse
+ 5
Please upload your code to the code playground and post a link here. Also, I'm not sure if anyone is going to try to understand what variables like n, k, s, t, u, c and q are for https://www.sololearn.com/discuss/1316935/?ref=app
20th Feb 2019, 12:58 PM
Anna
Anna - avatar