خرید بک لینک

Vote count: 0

I have to write a program that writes a program that uses the heap to store an array. I have a problem where the program will crash after successfully ruing it... I also have some small aesthetic problems, the element needs to start at 1 and no comma on the last number that is printed. Can anyone help?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int size = 0;
    int* num_elements;
    num_elements = (int*)malloc(sizeof(int)* 3);

    printf("How many int elements will you enter?");
    scanf("%d", &size);
    printf("n");

    for (int k = 0; k < size; k++)
    {
        printf("Element %d: ", k);
        scanf("%d", &num_elements[k]);
    }

    printf("n");

    printf("The Array stores the following values: ");

    for (int j = 0; j < size; j++)
    {
        printf("%d, ", num_elements[j]);
    }

    printf("n");

    free(num_elements);

    num_elements = 0;

    retu 0;
}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 خرداد 1395 ساعت: 19:51

صفحه بندی