Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.5 kB
1
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int *delElement(int arr[], int threshold, int *size_arr);

int main(void)
{
    int stu_id = 70357003;

    int arr[100], count = 0, threshold;
    printf("Enter a list of integer for an array separated by space: ");
    do{
        scanf("%d", &arr[count]);
        count++;
    }while(getchar() != '\n');

    printf("Please enter a desired threshold: ");
    scanf("%d", &threshold);

    int *ptr;
    ptr = delElement(&arr, threshold, count);

    printf("Modified Array: { ");
    for(int i = 0; i < count; i++){
        printf("%d ", *(ptr + i));
    }
    printf("}");

    printf("\n\nStudent ID: %d\n\n", stu_id);
    return 0;
}

int *delElement(int arr[], int threshold, int *size_arr){
    // Deleting elements smaller than threshold
    static int modified_arr[100];
    int count = 0;
    for(int i = 0; i < size_arr; i++){
        if(arr[i] >= threshold){
            modified_arr[count] = arr[i];
            count++;
        }
    }

    // Bubble Sort
    int temp = 0;
    for(int i = 0; i < count; i++){
        for(int j = 0; j < count - i - 1; j++){
            if(modified_arr[j] > modified_arr[j+1]){
                temp = modified_arr[j];
                modified_arr[j] = modified_arr[j+1];
                modified_arr[j+1] = temp;
            }
        }
    }

    *size_arr = count;

    return modified_arr;
}