• ПРОГРАММИРОВАНИЕ В СИ++.
    Ввести массив целых чисел, в котором есть нулевые элементы. Создать массив из номеров этих элементов. (Исправить ошибки в программе)
    #include <stdio.h>
    #include <iostream>
    #include <malloc.h>
    const int N = 10;
    int main()
    {
    setlocale(LC_ALL, "RUS");
    int i, n=0;
    int array[N];
    int *a;
    puts("Исходный массив:");
    for (int i = 0; i {
    printf_s("Введите %d элемент:", i);
    scanf_s("%d", &array[i]);
    }
    system("cls");
    puts("Исходный массив:");
    for (int i = 0; i {
    printf_s("%d", array[i]);
    }
    printf_s("");
    for (int i = 0; i {
    if (array[i] == 0)
    {
    n = n++;
    }
    }
    printf_s("Новый массив:");
    a = (int*)malloc(n*sizeof(int));
    for (i = 0; i {
    a[i] = 0;
    }
    for (i = 0; i {
    if (array[i] == 0)
    {
    a[i] = i;
    }
    }
    for (i = 0; i < n; i++)
    {
    printf_s("%d", a[i]);
    }
    free(a);
    printf_s("");
    system("pause");
    return 0;
    }

Ответы 1

  • #include <stdio.h>#include <iostream>#include <malloc.h>const int N = 10;int main(){setlocale(LC_ALL, "RUS");int i, j=0, n=0;int array[N];int *a;puts("Исходный массив:");for (i=0; i<N; i++) {printf("Введите %d элемент:", i);scanf("%d", &array[i]);}system("cls");puts("Исходный массив:");for (i=0; i<N; i++) {printf("%d ", array[i]);}printf("");for (i=0; i<N; i++)if (array[i] == 0)n++; printf("Новый массив:");a = (int *)malloc(n*sizeof(int));for (i=0; i<N; i++)  if (array[i] == 0) {    a[j] = i;    printf("%d ", a[j]);    j++;  }free(a);printf("");system("pause");return 0;}Тестовое решение:Исходный массив:5 0 3 6 0 0 2 1 0 5Новый массив:1 4 5 8Для продолжения нажмите любую клавишу . . .
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years