S
S
samsungovetch2018-07-11 09:42:32
C++ / C#
samsungovetch, 2018-07-11 09:42:32

C - How to make a separate function for array input from the keyboard and a function for output?

Hello, I understand C.
My disassembly led to this code

#include <stdio.h>



void main()
{
  int *a;//
  int n = 0;//

  printf("Введите размерность массива: ");
  scanf("%i", &n);

  a = (int*)malloc(n * sizeof(int));

  for (int i = 0; i<n; i++)
  {
    printf("a[%i] = ", i);
    scanf("%i", &a[i]);
  }
  free(a);
}

How now from this program to compose two functions that are called in main - a function for inputting an array of a certain length n, and a function for outputting an array to the console. Help me to understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-07-11
@jcmvbkbc

compose two functions called in main - a function to input an array of a certain length n, and a function to output an array to the console

1) understand what these functions will accept and return
2) move the input code to the first function
3) write the second function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question